From 8c105076caa730bcb13b9e31c590aa7e725705a8 Mon Sep 17 00:00:00 2001 From: Michail Yasonik Date: Tue, 16 Jun 2020 15:10:26 -0400 Subject: [PATCH 1/2] adding more keyboard shortcuts and instructions --- src/components/selectable/selectable.tsx | 16 +++++ .../selectable_list_item.test.tsx.snap | 9 ++- .../selectable_list/selectable_list.tsx | 1 + .../selectable_list/selectable_list_item.tsx | 68 +++++++++++++++++-- 4 files changed, 88 insertions(+), 6 deletions(-) diff --git a/src/components/selectable/selectable.tsx b/src/components/selectable/selectable.tsx index 08bc5b78aac..d9dcc91e067 100644 --- a/src/components/selectable/selectable.tsx +++ b/src/components/selectable/selectable.tsx @@ -220,6 +220,8 @@ export class EuiSelectable extends Component< break; case keys.ENTER: + case keys.SPACE: + event.preventDefault(); event.stopPropagation(); if (this.state.activeOptionIndex != null && optionsList) { optionsList.onAddOrRemoveOption( @@ -228,6 +230,20 @@ export class EuiSelectable extends Component< } break; + case keys.HOME: + event.preventDefault(); + event.stopPropagation(); + this.setState({ activeOptionIndex: 0 }); + break; + + case keys.END: + event.preventDefault(); + event.stopPropagation(); + this.setState({ + activeOptionIndex: this.state.visibleOptions.length - 1, + }); + break; + default: if (this.props.onKeyDown) { this.props.onKeyDown(event); diff --git a/src/components/selectable/selectable_list/__snapshots__/selectable_list_item.test.tsx.snap b/src/components/selectable/selectable_list/__snapshots__/selectable_list_item.test.tsx.snap index e471912970d..a6151277629 100644 --- a/src/components/selectable/selectable_list/__snapshots__/selectable_list_item.test.tsx.snap +++ b/src/components/selectable/selectable_list/__snapshots__/selectable_list_item.test.tsx.snap @@ -2,6 +2,7 @@ exports[`EuiSelectableListItem is rendered 1`] = `
  • @@ -70,6 +73,7 @@ exports[`EuiSelectableListItem props checked is off 1`] = ` exports[`EuiSelectableListItem props checked is on 1`] = `
  • { append={append} aria-posinset={index + 1 - labelCount} aria-setsize={data.length - labelCount} + allowExclusions={this.props.allowExclusions} {...optionRest as EuiSelectableListItemProps}> {this.props.renderOption ? ( this.props.renderOption(option, this.props.searchValue) diff --git a/src/components/selectable/selectable_list/selectable_list_item.tsx b/src/components/selectable/selectable_list/selectable_list_item.tsx index 68647420ab1..995d0ca6150 100644 --- a/src/components/selectable/selectable_list/selectable_list_item.tsx +++ b/src/components/selectable/selectable_list/selectable_list_item.tsx @@ -17,11 +17,13 @@ * under the License. */ -import React, { Component, LiHTMLAttributes } from 'react'; import classNames from 'classnames'; +import React, { Component, LiHTMLAttributes } from 'react'; import { CommonProps } from '../../common'; -import { EuiIcon, IconType, IconColor } from '../../icon'; +import { EuiI18n } from '../../i18n'; +import { EuiIcon, IconColor, IconType } from '../../icon'; import { EuiSelectableOptionCheckedType } from '../selectable_option'; +import { EuiScreenReaderOnly } from '../../accessibility'; function resolveIconAndColor( checked: EuiSelectableOptionCheckedType @@ -52,6 +54,7 @@ export type EuiSelectableListItemProps = LiHTMLAttributes & disabled?: boolean; prepend?: React.ReactNode; append?: React.ReactNode; + allowExclusions?: boolean; }; // eslint-disable-next-line react/prefer-stateless-function @@ -70,12 +73,13 @@ export class EuiSelectableListItem extends Component< const { children, className, - disabled, + disabled = false, checked, isFocused, showIcons, prepend, append, + allowExclusions, ...rest } = this.props; @@ -113,18 +117,72 @@ export class EuiSelectableListItem extends Component< ); } + let state: React.ReactNode; + let instruction: React.ReactNode; + if (allowExclusions && checked === 'on') { + state = ( + + + + + + ); + instruction = ( + + + + + + ); + } else if (allowExclusions && checked === 'off') { + state = ( + + + + + + ); + instruction = ( + + + + + + ); + } + + if (allowExclusions) { + console.log({ state, instruction }); + } + return (
  • {optionIcon} {prependNode} - {children} + + {state} + {children} + {instruction} + {appendNode}
  • From cc5a941e7473bdcc9e5ee1927b28458de3b18059 Mon Sep 17 00:00:00 2001 From: Michail Yasonik Date: Thu, 18 Jun 2020 13:23:34 -0400 Subject: [PATCH 2/2] deduping i18n keys --- .../selectable/selectable_list/selectable_list_item.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/selectable/selectable_list/selectable_list_item.tsx b/src/components/selectable/selectable_list/selectable_list_item.tsx index 995d0ca6150..7fe46002b2f 100644 --- a/src/components/selectable/selectable_list/selectable_list_item.tsx +++ b/src/components/selectable/selectable_list/selectable_list_item.tsx @@ -155,7 +155,7 @@ export class EuiSelectableListItem extends Component<