From f17f1a12f01b991fd54234fd866b6e078e03eb19 Mon Sep 17 00:00:00 2001 From: Emiel Van Severen Date: Fri, 1 Nov 2024 22:56:37 +0100 Subject: [PATCH] bugfix: always render select in portal --- .../data/Table/subcomponents/Filter/field.tsx | 2 -- .../Pagination/PageSizeSelect.tsx | 1 - .../DateRangePicker/QuickSelect/index.tsx | 2 -- .../subcomponents/RelativePicker/index.tsx | 2 -- .../inputs/DurationField/Generic.tsx | 1 - .../inputs/selects/SelectField/Controlled.tsx | 2 -- .../selects/SelectField/Generic/index.tsx | 20 ++++------- .../selects/SelectQueryField/Controlled.tsx | 2 -- .../SelectQueryField/Generic/index.tsx | 34 ++++++++++--------- .../JsonSchemaForm/widgets/ItemWidget.tsx | 1 - .../JsonSchemaForm/widgets/SelectWidget.tsx | 1 - .../selects/CountrySelectField/index.tsx | 2 -- .../selects/EventNameSelectField/index.tsx | 2 -- .../GameServerSelectQueryField/index.tsx | 4 --- .../selects/ItemSelectQueryField/index.tsx | 4 --- .../selects/ModuleSelectQueryField.tsx | 4 --- .../selects/PlayerSelectQueryField.tsx | 4 --- .../selects/RoleSelectQueryField.tsx | 4 --- .../selects/TimePeriodSelectField.tsx | 2 -- .../_global/user.$userId.role.assign.tsx | 2 +- .../-ShopListingCreateUpdateForm.tsx | 1 - .../shop.listing.import.gameserver.tsx | 1 - 22 files changed, 25 insertions(+), 73 deletions(-) diff --git a/packages/lib-components/src/components/data/Table/subcomponents/Filter/field.tsx b/packages/lib-components/src/components/data/Table/subcomponents/Filter/field.tsx index 3f80390d1d..824a910900 100644 --- a/packages/lib-components/src/components/data/Table/subcomponents/Filter/field.tsx +++ b/packages/lib-components/src/components/data/Table/subcomponents/Filter/field.tsx @@ -70,7 +70,6 @@ export function FilterRow({ control={control} name={`filters.${index}.column`} label="Column" - inPortal render={(selectedItems) => { if (selectedItems.length === 0) { return 'Select a column'; @@ -95,7 +94,6 @@ export function FilterRow({ control={control} name={`filters.${index}.operator`} label="Condition" - inPortal render={() => { const operator = currentOperator?.toString(); diff --git a/packages/lib-components/src/components/data/Table/subcomponents/Pagination/PageSizeSelect.tsx b/packages/lib-components/src/components/data/Table/subcomponents/Pagination/PageSizeSelect.tsx index d9d0f13189..520f966cb4 100644 --- a/packages/lib-components/src/components/data/Table/subcomponents/Pagination/PageSizeSelect.tsx +++ b/packages/lib-components/src/components/data/Table/subcomponents/Pagination/PageSizeSelect.tsx @@ -14,7 +14,6 @@ export const PageSizeSelect: FC = ({ onPageSizeChange, page id="page-size" multiple={false} name="pageSize" - inPortal={true} value={pageSize.toString() || '10'} onChange={onPageSizeChange} render={(selectedItems) => { diff --git a/packages/lib-components/src/components/inputs/Date/DateRangePicker/QuickSelect/index.tsx b/packages/lib-components/src/components/inputs/Date/DateRangePicker/QuickSelect/index.tsx index 8322e12f85..3358141cb4 100644 --- a/packages/lib-components/src/components/inputs/Date/DateRangePicker/QuickSelect/index.tsx +++ b/packages/lib-components/src/components/inputs/Date/DateRangePicker/QuickSelect/index.tsx @@ -99,7 +99,6 @@ export const QuickSelect: FC = ({ id }) => { ( @@ -120,7 +119,6 @@ export const QuickSelect: FC = ({ id }) => { ( diff --git a/packages/lib-components/src/components/inputs/Date/subcomponents/RelativePicker/index.tsx b/packages/lib-components/src/components/inputs/Date/subcomponents/RelativePicker/index.tsx index 5ca5533757..571077bded 100644 --- a/packages/lib-components/src/components/inputs/Date/subcomponents/RelativePicker/index.tsx +++ b/packages/lib-components/src/components/inputs/Date/subcomponents/RelativePicker/index.tsx @@ -99,7 +99,6 @@ export const RelativePicker: FC = ({ onChange, id, timeDire = ({ onChange, id, timeDire ( diff --git a/packages/lib-components/src/components/inputs/DurationField/Generic.tsx b/packages/lib-components/src/components/inputs/DurationField/Generic.tsx index 0dfd3098d8..251d7a5d1c 100644 --- a/packages/lib-components/src/components/inputs/DurationField/Generic.tsx +++ b/packages/lib-components/src/components/inputs/DurationField/Generic.tsx @@ -136,7 +136,6 @@ export const GenericDurationField = forwardRef & SubComponen control, loading, enableFilter, - inPortal, canClear, } = defaultsApplier(props); @@ -114,7 +113,6 @@ export const ControlledSelectField: FC & SubComponen onFocus={handleOnFocus} render={render} value={field.value} - inPortal={inPortal} > {children} diff --git a/packages/lib-components/src/components/inputs/selects/SelectField/Generic/index.tsx b/packages/lib-components/src/components/inputs/selects/SelectField/Generic/index.tsx index 4c027799d9..0afd169c75 100644 --- a/packages/lib-components/src/components/inputs/selects/SelectField/Generic/index.tsx +++ b/packages/lib-components/src/components/inputs/selects/SelectField/Generic/index.tsx @@ -12,7 +12,7 @@ import { MouseEvent, } from 'react'; import { GroupContainer, GroupLabel } from '../style'; -import { SelectContainer, StyledFloatingOverlay, StyledArrowIcon, SelectButton } from '../../sharedStyle'; +import { SelectContainer, StyledArrowIcon, SelectButton } from '../../sharedStyle'; import { FilterInput } from './FilterInput'; import { AiOutlineClose as ClearIcon } from 'react-icons/ai'; @@ -40,9 +40,6 @@ import { IconButton } from '../../../../../components/'; interface SharedSelectFieldProps { render: (selectedItems: SelectItem[]) => React.ReactNode; enableFilter?: boolean; - /// Rendering in portal will render the selectDropdown independent from its parent container. - /// this is useful when select is rendered in other floating elements with limited space. - inPortal?: boolean; /// When true, The select icon will be replaced by a cross icon to clear the selected value. canClear?: boolean; @@ -85,7 +82,6 @@ export const GenericSelectField: FC & SubComponentTypes hasError, hasDescription, name, - inPortal = false, disabled, enableFilter = false, multiple = false, @@ -116,14 +112,17 @@ export const GenericSelectField: FC & SubComponentTypes size({ apply({ availableHeight, elements, availableWidth }) { const refWidth = elements.reference.getBoundingClientRect().width; + const floatingContentWidth = elements.floating.scrollWidth; Object.assign(elements.floating.style, { // Note: we cannot use the rects.reference.width here because if the referenced item is very small compared to the other options, there will be horizontal overflow. // fit-content isn't the perfect solution either, because if there is no space available it might render outside the viewport. - width: availableWidth < refWidth ? `${availableWidth}px` : `${refWidth}px`, + minWidth: + availableWidth > refWidth ? `${availableWidth}px` : `${Math.max(refWidth, floatingContentWidth)}px`, maxHeight: `${Math.max(150, availableHeight)}px`, }); }, + padding: 10, }), flip({ fallbackStrategy: 'bestFit', @@ -286,14 +285,7 @@ export const GenericSelectField: FC & SubComponentTypes )} - {open && - (!inPortal ? ( - - {renderSelect()} - - ) : ( - {renderSelect()} - ))} + {open && {renderSelect()}} ); }; diff --git a/packages/lib-components/src/components/inputs/selects/SelectQueryField/Controlled.tsx b/packages/lib-components/src/components/inputs/selects/SelectQueryField/Controlled.tsx index 0aed75ecc0..6909a37160 100644 --- a/packages/lib-components/src/components/inputs/selects/SelectQueryField/Controlled.tsx +++ b/packages/lib-components/src/components/inputs/selects/SelectQueryField/Controlled.tsx @@ -26,7 +26,6 @@ export const ControlledSelectQueryField: FC & S name, multiple, control, - inPortal, debounce, isLoadingData, hasNextPage, @@ -83,7 +82,6 @@ export const ControlledSelectQueryField: FC & S multiple={multiple} required={required} size={componentSize} - inPortal={inPortal} onChange={field.onChange} onBlur={handleOnBlur} canClear={canClear} diff --git a/packages/lib-components/src/components/inputs/selects/SelectQueryField/Generic/index.tsx b/packages/lib-components/src/components/inputs/selects/SelectQueryField/Generic/index.tsx index c989a50811..e578e60307 100644 --- a/packages/lib-components/src/components/inputs/selects/SelectQueryField/Generic/index.tsx +++ b/packages/lib-components/src/components/inputs/selects/SelectQueryField/Generic/index.tsx @@ -16,6 +16,7 @@ import { FloatingPortal, size, useDismiss, + flip, useFloating, useInteractions, useRole, @@ -32,7 +33,7 @@ import { PaginationProps } from '../../../'; /* The SearchField depends on a few things of