Skip to content
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

[Discover] Move focus on chart toggle in Discover #103119

Merged
merged 2 commits into from
Jun 24, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/
import React, { useCallback } from 'react';
import React, { useCallback, useEffect, useRef } from 'react';
import moment from 'moment';
import { EuiFlexGroup, EuiFlexItem, EuiButtonEmpty, EuiSpacer } from '@elastic/eui';
import { IUiSettingsClient } from 'kibana/public';
Expand Down Expand Up @@ -47,8 +47,21 @@ export function DiscoverChart({
stateContainer: GetStateReturn;
timefield?: string;
}) {
const chartRef = useRef<{ element: HTMLElement | null; moveFocus: boolean }>({
element: null,
moveFocus: false,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do not moving focus on initial render by setting moveFocus to false

});

useEffect(() => {
if (chartRef.current.moveFocus && chartRef.current.element) {
chartRef.current.element.focus();
}
}, [state.hideChart]);

const toggleHideChart = useCallback(() => {
stateContainer.setAppState({ hideChart: !state.hideChart });
const newHideChart = !state.hideChart;
stateContainer.setAppState({ hideChart: newHideChart });
chartRef.current.moveFocus = !newHideChart;
}, [state, stateContainer]);

const onChangeInterval = useCallback(
Expand Down Expand Up @@ -102,9 +115,7 @@ export function DiscoverChart({
<EuiButtonEmpty
size="xs"
iconType={!state.hideChart ? 'eyeClosed' : 'eye'}
onClick={() => {
toggleHideChart();
}}
onClick={toggleHideChart}
data-test-subj="discoverChartToggle"
>
{!state.hideChart
Expand All @@ -122,6 +133,8 @@ export function DiscoverChart({
{!state.hideChart && chartData && (
<EuiFlexItem grow={false}>
<section
ref={(element) => (chartRef.current.element = element)}
tabIndex={-1}
aria-label={i18n.translate('discover.histogramOfFoundDocumentsAriaLabel', {
defaultMessage: 'Histogram of found documents',
})}
Expand Down