Skip to content

Adding Option To Allow Pushing Selected Items To The Top of Items #241

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 5 commits into
base: master
Choose a base branch
from
Open
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
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -142,6 +142,9 @@ yarn add react-native-element-dropdown
| itemTestIDField | String | No | Add this field to the input data. Ex: DATA = [{itemTestIDField: '', label: '', value:: ''}]|
| accessibilityLabel | String | No | Set an accessibilityLabel on the view, so that people who use VoiceOver know what element they have selected |
| itemAccessibilityLabelField | String | No | Add this field to the input data. Ex: DATA = [{itemAccessibilityLabelField: '', label: '', value:: ''}]|
|------|------|------|------|
| selectedToTop | Boolean | No | Put selected items on top of the list |
|------|------|------|------|



9 changes: 8 additions & 1 deletion src/components/MultiSelect/index.tsx
Original file line number Diff line number Diff line change
@@ -93,6 +93,7 @@ const MultiSelectComponent: <T>(
itemAccessibilityLabelField,
visibleSelectedItem = true,
mode = 'default',
selectedToTop = false,
} = props;

const ref = useRef<View>(null);
@@ -519,7 +520,13 @@ const MultiSelectComponent: <T>(
accessibilityLabel={accessibilityLabel + ' flatlist'}
{...flatListProps}
keyboardShouldPersistTaps="handled"
data={listData}
data={
selectedToTop
? listData
.filter((item) => checkSelected(item))
.concat(listData.filter((item) => !checkSelected(item)))
: listData
}
inverted={isTopPosition ? inverted : false}
renderItem={_renderItem}
keyExtractor={(_item, index) => index.toString()}
1 change: 1 addition & 0 deletions src/components/MultiSelect/model.ts
Original file line number Diff line number Diff line change
@@ -35,6 +35,7 @@ export interface MultiSelectProps<T> {
iconColor?: string;
activeColor?: string;
data: T[];
selectedToTop?: boolean;
value?: string[] | null | undefined;
placeholder?: string;
labelField: keyof T;