Skip to content

Commit

Permalink
[Lens] fix focus on legend action popovers (#115066) (#118231)
Browse files Browse the repository at this point in the history
  • Loading branch information
rshen91 authored Nov 10, 2021
1 parent f59fc87 commit ad9f62f
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 5 deletions.
9 changes: 7 additions & 2 deletions src/plugins/vis_types/pie/public/utils/get_legend_actions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import React, { useState, useEffect, useMemo } from 'react';

import { i18n } from '@kbn/i18n';
import { EuiContextMenuPanelDescriptor, EuiIcon, EuiPopover, EuiContextMenu } from '@elastic/eui';
import { LegendAction, SeriesIdentifier } from '@elastic/charts';
import { LegendAction, SeriesIdentifier, useLegendAction } from '@elastic/charts';
import { DataPublicPluginStart } from '../../../../data/public';
import { PieVisParams } from '../types';
import { ClickTriggerEvent } from '../../../../charts/public';
Expand All @@ -30,6 +30,7 @@ export const getLegendActions = (
const [popoverOpen, setPopoverOpen] = useState(false);
const [isfilterable, setIsfilterable] = useState(true);
const filterData = useMemo(() => getFilterEventData(pieSeries), [pieSeries]);
const [ref, onClose] = useLegendAction<HTMLDivElement>();

useEffect(() => {
(async () => setIsfilterable(await canFilter(filterData, actions)))();
Expand Down Expand Up @@ -82,6 +83,7 @@ export const getLegendActions = (
const Button = (
<div
tabIndex={0}
ref={ref}
role="button"
aria-pressed="false"
style={{
Expand All @@ -105,7 +107,10 @@ export const getLegendActions = (
id="contextMenuNormal"
button={Button}
isOpen={popoverOpen}
closePopover={() => setPopoverOpen(false)}
closePopover={() => {
setPopoverOpen(false);
onClose();
}}
panelPaddingSize="none"
anchorPosition="upLeft"
title={i18n.translate('visTypePie.legend.filterOptionsLegend', {
Expand Down
14 changes: 12 additions & 2 deletions src/plugins/vis_types/xy/public/utils/get_legend_actions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,12 @@ import React, { useState, useEffect, useMemo } from 'react';

import { i18n } from '@kbn/i18n';
import { EuiContextMenuPanelDescriptor, EuiIcon, EuiPopover, EuiContextMenu } from '@elastic/eui';
import { LegendAction, XYChartSeriesIdentifier, SeriesName } from '@elastic/charts';
import {
LegendAction,
XYChartSeriesIdentifier,
SeriesName,
useLegendAction,
} from '@elastic/charts';

import { ClickTriggerEvent } from '../../../../charts/public';

Expand All @@ -25,6 +30,7 @@ export const getLegendActions = (
const [isfilterable, setIsfilterable] = useState(false);
const series = xySeries as XYChartSeriesIdentifier;
const filterData = useMemo(() => getFilterEventData(series), [series]);
const [ref, onClose] = useLegendAction<HTMLDivElement>();

useEffect(() => {
(async () => setIsfilterable(await canFilter(filterData)))();
Expand Down Expand Up @@ -69,6 +75,7 @@ export const getLegendActions = (
const Button = (
<div
tabIndex={0}
ref={ref}
role="button"
aria-pressed="false"
style={{
Expand All @@ -92,7 +99,10 @@ export const getLegendActions = (
id="contextMenuNormal"
button={Button}
isOpen={popoverOpen}
closePopover={() => setPopoverOpen(false)}
closePopover={() => {
setPopoverOpen(false);
onClose();
}}
panelPaddingSize="none"
anchorPosition="upLeft"
title={i18n.translate('visTypeXy.legend.filterOptionsLegend', {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import React, { useState } from 'react';
import { i18n } from '@kbn/i18n';
import { EuiContextMenuPanelDescriptor, EuiIcon, EuiPopover, EuiContextMenu } from '@elastic/eui';
import { useLegendAction } from '@elastic/charts';
import type { LensFilterEvent } from '../types';

export interface LegendActionPopoverProps {
Expand All @@ -31,6 +32,7 @@ export const LegendActionPopover: React.FunctionComponent<LegendActionPopoverPro
context,
}) => {
const [popoverOpen, setPopoverOpen] = useState(false);
const [ref, onClose] = useLegendAction<HTMLDivElement>();
const panels: EuiContextMenuPanelDescriptor[] = [
{
id: 'main',
Expand Down Expand Up @@ -65,6 +67,7 @@ export const LegendActionPopover: React.FunctionComponent<LegendActionPopoverPro
const Button = (
<div
tabIndex={0}
ref={ref}
role="button"
aria-pressed="false"
style={{
Expand All @@ -87,7 +90,10 @@ export const LegendActionPopover: React.FunctionComponent<LegendActionPopoverPro
id="contextMenuNormal"
button={Button}
isOpen={popoverOpen}
closePopover={() => setPopoverOpen(false)}
closePopover={() => {
setPopoverOpen(false);
onClose();
}}
panelPaddingSize="none"
anchorPosition="upLeft"
title={i18n.translate('xpack.lens.shared.legend.filterOptionsLegend', {
Expand Down

0 comments on commit ad9f62f

Please sign in to comment.