-
Notifications
You must be signed in to change notification settings - Fork 840
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
feat: Add optionMatcher
prop to EuiSelectable
and EuiComboBox
components
#7709
Merged
tkajtoch
merged 8 commits into
elastic:main
from
tkajtoch:feat/combobox-seletable-matcher
Apr 29, 2024
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
e28fcf9
feat(EuiComboBox): Add `optionMatcher` prop to allow passing custom o…
tkajtoch e293461
feat(EuiSelectable): Add `optionMatcher` prop to allow passing custom…
tkajtoch 00729ae
test: fix failing tests
tkajtoch 0f08ac1
style: fix matching_options.test.ts formatting
tkajtoch 835bac3
chore: add changelog
tkajtoch b0b9b19
docs(EuiComboBox): add `optionMatcher` section and example
tkajtoch 6cc9f8a
docs(EuiSelectable): add `optionMatcher` section and example
tkajtoch d718bf7
fix(EuiSelectableSearchProps): fix `optionMatcher` jsdoc
tkajtoch File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
- Added a new, optional `optionMatcher` prop to `EuiSelectable` and `EuiComboBox` allowing passing a custom option matcher function to these components and controlling option filtering for given search string |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
import React, { useCallback, useState } from 'react'; | ||
|
||
import { | ||
EuiComboBox, | ||
EuiComboBoxOptionOption, | ||
EuiComboBoxOptionMatcher, | ||
} from '../../../../src'; | ||
|
||
const options: EuiComboBoxOptionOption[] = [ | ||
{ | ||
label: 'Titan', | ||
'data-test-subj': 'titanOption', | ||
}, | ||
{ | ||
label: 'Enceladus', | ||
}, | ||
{ | ||
label: 'Mimas', | ||
}, | ||
{ | ||
label: 'Dione', | ||
}, | ||
{ | ||
label: 'Iapetus', | ||
}, | ||
{ | ||
label: 'Phoebe', | ||
}, | ||
{ | ||
label: 'Rhea', | ||
}, | ||
{ | ||
label: | ||
"Pandora is one of Saturn's moons, named for a Titaness of Greek mythology", | ||
}, | ||
{ | ||
label: 'Tethys', | ||
}, | ||
{ | ||
label: 'Hyperion', | ||
}, | ||
]; | ||
|
||
export default () => { | ||
const [selectedOptions, setSelected] = useState<EuiComboBoxOptionOption[]>( | ||
[] | ||
); | ||
const onChange = (selectedOptions: EuiComboBoxOptionOption[]) => { | ||
setSelected(selectedOptions); | ||
}; | ||
|
||
const startsWithMatcher = useCallback<EuiComboBoxOptionMatcher<unknown>>( | ||
({ option, searchValue }) => { | ||
return option.label.startsWith(searchValue); | ||
}, | ||
[] | ||
); | ||
|
||
return ( | ||
<EuiComboBox | ||
placeholder="Select options" | ||
options={options} | ||
selectedOptions={selectedOptions} | ||
onChange={onChange} | ||
isClearable={true} | ||
optionMatcher={startsWithMatcher} | ||
/> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
71 changes: 71 additions & 0 deletions
71
src-docs/src/views/selectable/selectable_option_matcher.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
import React, { useCallback, useState } from 'react'; | ||
|
||
import { EuiSelectable, EuiSelectableOption } from '../../../../src'; | ||
import { EuiSelectableOptionMatcher } from '../../../../src/components/selectable/selectable'; | ||
|
||
export default () => { | ||
const [options, setOptions] = useState<EuiSelectableOption[]>([ | ||
{ | ||
label: 'Titan', | ||
'data-test-subj': 'titanOption', | ||
}, | ||
{ | ||
label: 'Enceladus is disabled', | ||
disabled: true, | ||
}, | ||
{ | ||
label: 'Mimas', | ||
checked: 'on', | ||
}, | ||
{ | ||
label: 'Dione', | ||
}, | ||
{ | ||
label: 'Iapetus', | ||
checked: 'on', | ||
}, | ||
{ | ||
label: 'Phoebe', | ||
}, | ||
{ | ||
label: 'Rhea', | ||
}, | ||
{ | ||
label: | ||
"Pandora is one of Saturn's moons, named for a Titaness of Greek mythology", | ||
}, | ||
{ | ||
label: 'Tethys', | ||
}, | ||
{ | ||
label: 'Hyperion', | ||
}, | ||
]); | ||
|
||
const startsWithMatcher = useCallback<EuiSelectableOptionMatcher<unknown>>( | ||
({ option, searchValue }) => { | ||
return option.label.startsWith(searchValue); | ||
}, | ||
[] | ||
); | ||
|
||
return ( | ||
<EuiSelectable | ||
aria-label="Searchable example" | ||
searchable | ||
searchProps={{ | ||
'data-test-subj': 'selectableSearchHere', | ||
}} | ||
options={options} | ||
onChange={(newOptions) => setOptions(newOptions)} | ||
optionMatcher={startsWithMatcher} | ||
> | ||
{(list, search) => ( | ||
<> | ||
{search} | ||
{list} | ||
</> | ||
)} | ||
</EuiSelectable> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🗒️ A general note, mainly for myself here:
Whenever we align on the
code-snippet
API in this PR and merge it, this story needs to be updated as it's a case of "additional composition wrapper" (it will likely need theparameters.codeSnippet.resolveChildren: true
as otherwise this story snippet would be<Render anyStoryArgsHere />
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the case for many of our stories, though, isn't it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some for sure. There are different cases I've seen so far. It depends on what should be output per story.
E.g. for cases like stateful wrappers that return just the actual story component it's different than a wrapper that returns the story component as nested child with other composition elements.
For stateful wrappers or related wrappers (Where a parent-subcomponent structure is required and can be determined based on naming it's already done automatically)
For anything else it might need adjustments.
I'm currently checking the newly added stories and there are some new cases as well that I did not consider yet (render functions 🙈)