diff --git a/src/components/Dropdown/Dropdown.tsx b/src/components/Dropdown/Dropdown.tsx index 07c581e..dcde9cc 100644 --- a/src/components/Dropdown/Dropdown.tsx +++ b/src/components/Dropdown/Dropdown.tsx @@ -24,7 +24,7 @@ const Dropdown: FCCWD = ( onSelect, rowTextStyle, containerStyle, - autoPosition = true, + direction = 'auto', size = 'medium', disabled, defaultValue = {}, @@ -144,10 +144,10 @@ const Dropdown: FCCWD = ( }, { maxHeight: sizes[size].rowHeight * 4.5 }, listContainerStyle, - autoPosition ? + direction === 'auto' ? (cord?.y + (sizes[size].rowHeight * 4.5) + 10 + sizes[size].buttonHeight || 0) >= windowsHeight ? { bottom: cord?.height } : { top: 0 } - : { top: cord?.height + 5 }, + : (direction === 'down' ? { top: 0 } : { bottom: cord?.height }), { backgroundColor: statusTheme.collapseBackground }]} > diff --git a/src/components/Dropdown/MultipleSelectDropdown.tsx b/src/components/Dropdown/MultipleSelectDropdown.tsx index 789fc2f..bb09af7 100644 --- a/src/components/Dropdown/MultipleSelectDropdown.tsx +++ b/src/components/Dropdown/MultipleSelectDropdown.tsx @@ -41,6 +41,7 @@ const MultipleDropdown: FCCWD = ( completeButtonLabelStyle, completeButtonLabel, overflowButtonLabel, + direction = 'auto', selectallButtonLabel }, ) => { const [visible, setVisible] = useState(false); @@ -133,6 +134,7 @@ const MultipleDropdown: FCCWD = ( ref={dropdown} activeOpacity={0.9} disabled={disabled} + onLayout={event => setCord(event.nativeEvent.layout)} onPress={() => { setVisible(!visible); }} style={[Style.button, { borderWidth: 1, height: sizes[size].buttonHeight }, @@ -191,10 +193,10 @@ const MultipleDropdown: FCCWD = ( maxHeight: selectall ? sizes[size].rowHeight * 6.5 : sizes[size].rowHeight * 6, }, listContainerStyle, - - // eslint-disable-next-line no-unsafe-optional-chaining - (cord?.y + (sizes[size].rowHeight * 6.5) || 0) >= windowsHeight ? - { bottom: cord?.height || 0 } : { top: 0 }, + direction === 'auto' ? + (cord.y + (sizes[size].rowHeight * 4.5) + 10 + sizes[size].buttonHeight || 0) >= windowsHeight ? + { bottom: cord?.height } : { top: 0 } + : (direction === 'down' ? { top: 0 } : { bottom: cord?.height }), { backgroundColor: statusTheme.collapseBackground }]} > diff --git a/src/types.ts b/src/types.ts index fc9a9b4..d07115f 100644 --- a/src/types.ts +++ b/src/types.ts @@ -407,9 +407,11 @@ export type DrowdownProps = { */ onComplete?: (item: any) => void, /** - *Controls whether the dropdown component's dropdown menu is positioned automatically. Defaults to true - */ - autoPosition?: boolean, + * Controls the dropdown menu's opening direction. + * Accepts 'up' or 'down' for specific directions, or 'auto' to adjust direction automatically based on available space. + * Defaults to 'auto'. + */ + direction?:'up'|'down'|'auto' /** *The theme to use for the component */