-
Notifications
You must be signed in to change notification settings - Fork 861
[docs] Add example of EuiSelectable in an EuiInputPopover
#7683
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
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
84add4b
Add an accessible example of EuiSelectable & EuiInputPopover
cee-chen d751965
Switch initial checked to only one option to account for the new sing…
cee-chen 2476f38
Split out popover and flyout examples into their own subcomponents fo…
cee-chen 103a3dd
Fix UX bugs via internal prop override 😬
cee-chen 51f951a
Extend `isPreFiltered` API to allow disabling search highlighting as …
cee-chen b400a4d
[wtf] Fix Chromium onBlur shenanigans
cee-chen eefdc7e
[PR feedback] typing
cee-chen 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 hidden or 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 @@ | ||
| - Updated `EuiSelectable`'s `isPreFiltered` prop to allow passing a configuration object, which allows disabling search highlighting in addition to search filtering |
This file contains hidden or 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 |
|---|---|---|
|
|
@@ -9,102 +9,154 @@ import { | |
| EuiPopoverFooter, | ||
| EuiPopoverTitle, | ||
| EuiSelectable, | ||
| EuiSelectableOption, | ||
| type EuiSelectableOption, | ||
| type EuiSelectableProps, | ||
| EuiSpacer, | ||
| EuiTitle, | ||
| EuiInputPopover, | ||
| } from '../../../../src'; | ||
|
|
||
| export default () => { | ||
| const [isPopoverOpen, setIsPopoverOpen] = useState(false); | ||
| const [isFlyoutVisible, setIsFlyoutVisible] = useState(false); | ||
| const OPTIONS: EuiSelectableOption[] = [ | ||
| { label: 'Titan' }, | ||
| { label: 'Enceladus' }, | ||
| { label: 'Mimas', checked: 'on' }, | ||
| { label: 'Dione' }, | ||
| { label: 'Iapetus' }, | ||
| { label: 'Phoebe' }, | ||
| { label: 'Rhea' }, | ||
| { label: 'Pandora' }, | ||
| { label: 'Tethys' }, | ||
| { label: 'Hyperion' }, | ||
| { label: 'Pan' }, | ||
| { label: 'Atlas' }, | ||
| { label: 'Prometheus' }, | ||
| { label: 'Janus' }, | ||
| { label: 'Epimetheus' }, | ||
| { label: 'Amalthea' }, | ||
| { label: 'Thebe' }, | ||
| { label: 'Io' }, | ||
| { label: 'Europa' }, | ||
| { label: 'Ganymede' }, | ||
| { label: 'Callisto' }, | ||
| { label: 'Himalia' }, | ||
| { label: 'Phobos' }, | ||
| { label: 'Deimos' }, | ||
| { label: 'Puck' }, | ||
| { label: 'Miranda' }, | ||
| { label: 'Ariel' }, | ||
| { label: 'Umbriel' }, | ||
| { label: 'Titania' }, | ||
| { label: 'Oberon' }, | ||
| { label: 'Despina' }, | ||
| { label: 'Galatea' }, | ||
| { label: 'Larissa' }, | ||
| { label: 'Triton' }, | ||
| { label: 'Nereid' }, | ||
| { label: 'Charon' }, | ||
| { label: 'Styx' }, | ||
| { label: 'Nix' }, | ||
| { label: 'Kerberos' }, | ||
| { label: 'Hydra' }, | ||
| ]; | ||
|
|
||
| const [options, setOptions] = useState<EuiSelectableOption[]>([ | ||
| { label: 'Titan' }, | ||
| { label: 'Enceladus' }, | ||
| { label: 'Mimas', checked: 'on' }, | ||
| { label: 'Dione' }, | ||
| { label: 'Iapetus', checked: 'on' }, | ||
| { label: 'Phoebe' }, | ||
| { label: 'Rhea' }, | ||
| { label: 'Pandora' }, | ||
| { label: 'Tethys' }, | ||
| { label: 'Hyperion' }, | ||
| { label: 'Pan' }, | ||
| { label: 'Atlas' }, | ||
| { label: 'Prometheus' }, | ||
| { label: 'Janus' }, | ||
| { label: 'Epimetheus' }, | ||
| { label: 'Amalthea' }, | ||
| { label: 'Thebe' }, | ||
| { label: 'Io' }, | ||
| { label: 'Europa' }, | ||
| { label: 'Ganymede' }, | ||
| { label: 'Callisto' }, | ||
| { label: 'Himalia' }, | ||
| { label: 'Phobos' }, | ||
| { label: 'Deimos' }, | ||
| { label: 'Puck' }, | ||
| { label: 'Miranda' }, | ||
| { label: 'Ariel' }, | ||
| { label: 'Umbriel' }, | ||
| { label: 'Titania' }, | ||
| { label: 'Oberon' }, | ||
| { label: 'Despina' }, | ||
| { label: 'Galatea' }, | ||
| { label: 'Larissa' }, | ||
| { label: 'Triton' }, | ||
| { label: 'Nereid' }, | ||
| { label: 'Charon' }, | ||
| { label: 'Styx' }, | ||
| { label: 'Nix' }, | ||
| { label: 'Kerberos' }, | ||
| { label: 'Hydra' }, | ||
| ]); | ||
| export default () => { | ||
| const [options, setOptions] = useState<EuiSelectableOption[]>(OPTIONS); | ||
| const onChange = (options: EuiSelectableOption[]) => { | ||
| setOptions(options); | ||
| }; | ||
|
|
||
| return ( | ||
| <> | ||
| <EuiPopover | ||
| panelPaddingSize="none" | ||
| button={ | ||
| <EuiButton | ||
| iconType="arrowDown" | ||
| iconSide="right" | ||
| onClick={() => setIsPopoverOpen(!isPopoverOpen)} | ||
| > | ||
| Show popover | ||
| </EuiButton> | ||
| } | ||
| isOpen={isPopoverOpen} | ||
| closePopover={() => setIsPopoverOpen(false)} | ||
| <SelectablePopover options={options} onChange={onChange} /> | ||
| <EuiSpacer /> | ||
|
|
||
| <SelectableFlyout options={options} onChange={onChange} /> | ||
| <EuiSpacer /> | ||
|
|
||
| <EuiTitle size="xxs"> | ||
| <h4>In an input popover</h4> | ||
| </EuiTitle> | ||
| <EuiSpacer size="s" /> | ||
| <SelectableInputPopover /> | ||
| <EuiSpacer /> | ||
|
|
||
| <EuiTitle size="xxs"> | ||
| <h4> | ||
| Using <EuiCode language="js">listProps.bordered=true</EuiCode> and{' '} | ||
| <EuiCode language="js"> | ||
| listProps.paddingSize="none" | ||
| </EuiCode> | ||
| </h4> | ||
| </EuiTitle> | ||
| <EuiSpacer size="s" /> | ||
| <EuiSelectable | ||
| aria-label="Bordered selectable example" | ||
| options={options} | ||
| onChange={onChange} | ||
| style={{ width: 300 }} | ||
| listProps={{ bordered: true, paddingSize: 'none' }} | ||
| > | ||
| <EuiSelectable | ||
| searchable | ||
| searchProps={{ | ||
| placeholder: 'Filter list', | ||
| compressed: true, | ||
| }} | ||
| options={options} | ||
| onChange={onChange} | ||
| {(list) => list} | ||
| </EuiSelectable> | ||
| </> | ||
| ); | ||
| }; | ||
|
|
||
| const SelectablePopover = ( | ||
| props: Pick<EuiSelectableProps, 'options' | 'onChange'> | ||
| ) => { | ||
| const [isPopoverOpen, setIsPopoverOpen] = useState(false); | ||
| const { options, onChange } = props; | ||
|
|
||
| return ( | ||
| <EuiPopover | ||
| panelPaddingSize="none" | ||
| button={ | ||
| <EuiButton | ||
| iconType="arrowDown" | ||
| iconSide="right" | ||
| onClick={() => setIsPopoverOpen(!isPopoverOpen)} | ||
| > | ||
| {(list, search) => ( | ||
| <div style={{ width: 240 }}> | ||
| <EuiPopoverTitle paddingSize="s">{search}</EuiPopoverTitle> | ||
| {list} | ||
| <EuiPopoverFooter paddingSize="s"> | ||
| <EuiButton size="s" fullWidth> | ||
| Manage this list | ||
| </EuiButton> | ||
| </EuiPopoverFooter> | ||
| </div> | ||
| )} | ||
| </EuiSelectable> | ||
| </EuiPopover> | ||
| Show popover | ||
| </EuiButton> | ||
| } | ||
| isOpen={isPopoverOpen} | ||
| closePopover={() => setIsPopoverOpen(false)} | ||
| > | ||
| <EuiSelectable | ||
| aria-label="Selectable + popover example" | ||
| searchable | ||
| searchProps={{ | ||
| placeholder: 'Filter list', | ||
| compressed: true, | ||
| }} | ||
| options={options} | ||
| onChange={onChange} | ||
| > | ||
| {(list, search) => ( | ||
| <div style={{ width: 240 }}> | ||
| <EuiPopoverTitle paddingSize="s">{search}</EuiPopoverTitle> | ||
| {list} | ||
| <EuiPopoverFooter paddingSize="s"> | ||
| <EuiButton size="s" fullWidth> | ||
| Manage this list | ||
| </EuiButton> | ||
| </EuiPopoverFooter> | ||
| </div> | ||
| )} | ||
| </EuiSelectable> | ||
| </EuiPopover> | ||
| ); | ||
| }; | ||
|
|
||
| <EuiSpacer /> | ||
| const SelectableFlyout = ( | ||
| props: Pick<EuiSelectableProps, 'options' | 'onChange'> | ||
| ) => { | ||
| const [isFlyoutVisible, setIsFlyoutVisible] = useState(false); | ||
| const { options, onChange } = props; | ||
|
|
||
| return ( | ||
| <> | ||
| <EuiButton onClick={() => setIsFlyoutVisible(true)}> | ||
| Show flyout | ||
| </EuiButton> | ||
|
|
@@ -116,7 +168,7 @@ export default () => { | |
| aria-labelledby="selectableFlyout" | ||
| > | ||
| <EuiSelectable | ||
| aria-label="Popover example" | ||
| aria-label="Selectable + flyout example" | ||
| searchable | ||
| options={options} | ||
| onChange={onChange} | ||
|
|
@@ -142,29 +194,63 @@ export default () => { | |
| </EuiFlyoutFooter> | ||
| </EuiFlyout> | ||
| )} | ||
| </> | ||
| ); | ||
| }; | ||
|
|
||
| <EuiSpacer /> | ||
|
|
||
| <EuiTitle size="xxs"> | ||
| <h4> | ||
| Using <EuiCode language="js">listProps.bordered=true</EuiCode> and{' '} | ||
| <EuiCode language="js"> | ||
| listProps.paddingSize="none" | ||
| </EuiCode> | ||
| </h4> | ||
| </EuiTitle> | ||
| const SelectableInputPopover = () => { | ||
| const [options, setOptions] = useState<EuiSelectableOption[]>(OPTIONS); | ||
| const [isOpen, setIsOpen] = useState(false); | ||
| const [inputValue, setInputValue] = useState(''); | ||
| const [isSearching, setIsSearching] = useState(true); | ||
|
|
||
| <EuiSpacer /> | ||
| return ( | ||
| <EuiSelectable | ||
| aria-label="Selectable + input popover example" | ||
| options={options} | ||
| onChange={(newOptions, event, changedOption) => { | ||
| setOptions(newOptions); | ||
| setIsOpen(false); | ||
|
|
||
| <EuiSelectable | ||
| aria-label="Bordered selectable example" | ||
| options={options} | ||
| onChange={onChange} | ||
| style={{ width: 300 }} | ||
| listProps={{ bordered: true, paddingSize: 'none' }} | ||
| > | ||
| {(list) => list} | ||
| </EuiSelectable> | ||
| </> | ||
| if (changedOption.checked === 'on') { | ||
| setInputValue(changedOption.label); | ||
| setIsSearching(false); | ||
| } else { | ||
| setInputValue(''); | ||
| } | ||
| }} | ||
| singleSelection | ||
| searchable | ||
| searchProps={{ | ||
| value: inputValue, | ||
| onChange: (value) => { | ||
| setInputValue(value); | ||
| setIsSearching(true); | ||
| }, | ||
| onKeyDown: (event) => { | ||
| if (event.key === 'Tab') return setIsOpen(false); | ||
cee-chen marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| if (event.key !== 'Escape') return setIsOpen(true); | ||
| }, | ||
| onClick: () => setIsOpen(true), | ||
| onFocus: () => setIsOpen(true), | ||
| }} | ||
| isPreFiltered={isSearching ? false : { highlightSearch: false }} // Shows the full list when not actively typing to search | ||
| listProps={{ | ||
| css: { '.euiSelectableList__list': { maxBlockSize: 200 } }, | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Although the requests we've received have had it, I didn't add |
||
| }} | ||
| > | ||
| {(list, search) => ( | ||
| <EuiInputPopover | ||
| closePopover={() => setIsOpen(false)} | ||
| disableFocusTrap | ||
| closeOnScroll | ||
| isOpen={isOpen} | ||
| input={search!} | ||
| panelPaddingSize="none" | ||
| > | ||
| {list} | ||
| </EuiInputPopover> | ||
| )} | ||
| </EuiSelectable> | ||
| ); | ||
| }; | ||
This file contains hidden or 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.
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.
Uh oh!
There was an error while loading. Please reload this page.