Skip to content

feat: Added direction prop to dropdown component. #251

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/components/Dropdown/Dropdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ const Dropdown: FCCWD<DrowdownProps> = (
onSelect,
rowTextStyle,
containerStyle,
autoPosition = true,
direction = 'auto',
size = 'medium',
disabled,
defaultValue = {},
Expand Down Expand Up @@ -144,10 +144,10 @@ const Dropdown: FCCWD<DrowdownProps> = (
},
{ 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 }]}
>
<ScrollView nestedScrollEnabled>
Expand Down
10 changes: 6 additions & 4 deletions src/components/Dropdown/MultipleSelectDropdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ const MultipleDropdown: FCCWD<MultipleDropdownProps> = (
completeButtonLabelStyle,
completeButtonLabel,
overflowButtonLabel,
direction = 'auto',
selectallButtonLabel },
) => {
const [visible, setVisible] = useState(false);
Expand Down Expand Up @@ -133,6 +134,7 @@ const MultipleDropdown: FCCWD<MultipleDropdownProps> = (
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 },
Expand Down Expand Up @@ -191,10 +193,10 @@ const MultipleDropdown: FCCWD<MultipleDropdownProps> = (
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 }]}
>
<ScrollView>
Expand Down
8 changes: 5 additions & 3 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down