Skip to content

Commit

Permalink
💄 [#4693] Use portalling to prevent hidden overflow of react-select menu
Browse files Browse the repository at this point in the history
  • Loading branch information
sergei-maertens committed Nov 18, 2024
1 parent 951fd64 commit 4716f4b
Show file tree
Hide file tree
Showing 7 changed files with 9 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,6 @@ const ObjectsAPIFields = ({errors}) => {
}}
name="options.objectsApiGroup"
onApiGroupChange={onApiGroupChange}
selectProps={{maxMenuHeight: '16em', menuPlacement: 'bottom'}}
/>

<ErrorBoundary
Expand All @@ -215,7 +214,6 @@ const ObjectsAPIFields = ({errors}) => {
name="options.objecttypeUuid"
apiGroupFieldName="options.objectsApiGroup"
versionFieldName="options.objecttypeVersion"
selectProps={{maxMenuHeight: '16em', menuPlacement: 'bottom'}}
onChangeCheck={async () => {
if (variablesMapping.length === 0) return true;
const confirmSwitch = await openObjectTypeConfirmationModal();
Expand All @@ -240,7 +238,6 @@ const ObjectsAPIFields = ({errors}) => {
name="options.objecttypeVersion"
apiGroupFieldName="options.objectsApiGroup"
objectTypeFieldName="options.objecttypeUuid"
selectProps={{maxMenuHeight: '16em', menuPlacement: 'bottom'}}
/>
</ErrorBoundary>

Expand Down
2 changes: 2 additions & 0 deletions src/openforms/js/components/admin/forms/ReactSelect.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ const SelectWithoutFormik = ({name, options, value, className, onChange, ...prop
classNamePrefix="admin-react-select"
styles={styles}
menuPlacement="auto"
menuPortalTarget={document.body}
options={options}
value={getValue(options, value)}
onChange={selectedOption => {
Expand All @@ -107,6 +108,7 @@ const SelectWithFormik = ({name, options, className, ...props}) => {
classNamePrefix="admin-react-select"
styles={styles}
menuPlacement="auto"
menuPortalTarget={document.body}
options={options}
{...fieldProps}
value={getValue(options, value)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ const ObjectTypeSelect = ({
apiGroupFieldName = 'objectsApiGroup',
onChangeCheck,
versionFieldName = 'objecttypeVersion',
selectProps = {},
}) => {
const [fieldProps, , fieldHelpers] = useField(name);
const {
Expand Down Expand Up @@ -95,7 +94,6 @@ const ObjectTypeSelect = ({
const okToProceed = onChangeCheck === undefined || onChangeCheck();
if (okToProceed) setValue(selectedOption.value);
}}
{...selectProps}
/>
</Field>
</FormRow>
Expand All @@ -122,11 +120,6 @@ ObjectTypeSelect.propTypes = {
* changes, the version will be reset/unset.
*/
versionFieldName: PropTypes.string,

/**
* Additional properties to be forwarded to the React select component
*/
selectProps: PropTypes.object,
};

export default ObjectTypeSelect;
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ const ObjectTypeVersionSelect = ({
name = 'objecttypeVersion',
apiGroupFieldName = 'objectsApiGroup',
objectTypeFieldName = 'objecttype',
selectProps = {},
}) => {
const {getFieldProps} = useFormikContext();

Expand Down Expand Up @@ -72,7 +71,6 @@ const ObjectTypeVersionSelect = ({
options={options}
isLoading={loading}
isDisabled={!objecttype}
{...selectProps}
/>
</Field>
</FormRow>
Expand All @@ -94,10 +92,6 @@ ObjectTypeVersionSelect.propTypes = {
* call to get the available object type versions.
*/
objectTypeFieldName: PropTypes.string,
/**
* Additional properties to be forwarded to the React select component
*/
selectProps: PropTypes.object,
};

export default ObjectTypeVersionSelect;
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ const ObjectsAPIGroup = ({
onApiGroupChange,
isClearable = false,
required = true,
selectProps = {},
}) => {
const [{onChange: onChangeFormik, ...fieldProps}, , {setValue}] = useField(name);
const {setValues} = useFormikContext();
Expand Down Expand Up @@ -69,7 +68,6 @@ const ObjectsAPIGroup = ({
}
}}
isClearable={isClearable}
{...selectProps}
/>
</Field>
</FormRow>
Expand Down Expand Up @@ -121,11 +119,6 @@ ObjectsAPIGroup.propTypes = {
* Indicate if the field is required or optional.
*/
required: PropTypes.bool,

/**
* Additional properties to be forwarded to the React select component
*/
selectProps: PropTypes.object,
};

export default ObjectsAPIGroup;
4 changes: 3 additions & 1 deletion src/openforms/scss/components/admin/_ReactModal.scss
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
align-items: center;

position: fixed;
z-index: 1000;
// the base admin layout gets a z-index up until 2, so this ensures it's layered on top of the admin
// while leaving enough space for other UI elements on top of that (like react-select)
z-index: 3;
top: 0;
right: 0;
bottom: 0;
Expand Down
4 changes: 4 additions & 0 deletions src/openforms/scss/vendor/_react-select.scss
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,8 @@
var(--of-admin-select-max-inline-size)
);
max-inline-size: var(--of-admin-select-max-inline-size);

&__menu-portal {
z-index: 4 !important; // one higher than the react-modal z-index
}
}

0 comments on commit 4716f4b

Please sign in to comment.