Skip to content

Commit

Permalink
fix(a11y): restore focus after popover close with color picker (#1272)
Browse files Browse the repository at this point in the history
Fixes #1266 and #935
  • Loading branch information
rshen91 authored Aug 31, 2021
1 parent cc37247 commit 0c6f945
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
1 change: 1 addition & 0 deletions packages/charts/src/components/legend/legend_item.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ export class LegendListItem extends Component<LegendItemProps, LegendItemState>
const handleClose = () => {
setPersistedColorAction(seriesKeys, this.shouldClearPersistedColor ? null : color);
clearTemporaryColorsAction();
requestAnimationFrame(() => this.colorRef?.current?.focus());
this.toggleIsOpen();
};
const handleChange = (c: Color | null) => {
Expand Down
5 changes: 2 additions & 3 deletions storybook/stories/legend/9_color_picker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,14 @@ import { BARCHART_1Y1G } from '@elastic/charts/src/utils/data_samples/test_datas
import { useBaseTheme } from '../../use_base_theme';

const onChangeAction = action('onChange');
const onCloseAction = action('onClose');

export const Example = () => {
const [colors, setColors] = useState<Record<SeriesKey, Color | null>>({});

const CustomColorPicker: LegendColorPicker = useMemo(
() => ({ anchor, color, onClose, seriesIdentifiers, onChange }) => {
const handleClose = () => {
onClose();
onCloseAction();
setColors((prevColors) => ({
...prevColors,
...toEntries(seriesIdentifiers, 'key', color),
Expand All @@ -52,7 +51,7 @@ export const Example = () => {

return (
<>
<EuiWrappingPopover isOpen button={anchor} closePopover={handleClose} anchorPosition="leftCenter" ownFocus>
<EuiWrappingPopover isOpen button={anchor} closePopover={handleClose} anchorPosition="leftCenter">
<EuiColorPicker display="inline" color={color} onChange={handleChange} />
<EuiSpacer size="m" />
<EuiFlexItem grow={false}>
Expand Down

0 comments on commit 0c6f945

Please sign in to comment.