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

feat(legend): add keyboard navigation #880

Merged
merged 56 commits into from
Dec 9, 2020
Merged
Show file tree
Hide file tree
Changes from 15 commits
Commits
Show all changes
56 commits
Select commit Hold shift + click to select a range
8846dd2
feat: add tabbing into legend
rshen91 Oct 27, 2020
3f66d55
Merge remote-tracking branch 'upstream/master' into legend-keyboard
rshen91 Oct 27, 2020
b85af45
feat: add focus to navigation of legend
rshen91 Oct 28, 2020
5342cc8
style: fixing echLegendLlistContainer orientation
rshen91 Oct 29, 2020
5bfd8ab
fix: remove outer button fixing style issues
rshen91 Oct 30, 2020
7ded2df
test: update unit tests
rshen91 Oct 30, 2020
f783dba
fix: improve navigation for action story
rshen91 Nov 3, 2020
16fcfa7
feat: add screen reader for extra
rshen91 Nov 6, 2020
d0d4a2e
Merge remote-tracking branch 'upstream/master' into legend-keyboard
rshen91 Nov 6, 2020
c4b60e1
Merge remote-tracking branch 'upstream/master' into legend-keyboard
rshen91 Nov 6, 2020
cfd84a6
fix: change aria label and unit test snapshots
rshen91 Nov 9, 2020
8bafadd
test: update vrts
rshen91 Nov 9, 2020
09c1048
Merge remote-tracking branch 'upstream/master' into legend-keyboard
rshen91 Nov 11, 2020
69c528f
refactor: add some cleanup
rshen91 Nov 11, 2020
835655f
test: revert vrt updates
rshen91 Nov 11, 2020
4637ccc
feat: initial review changes
rshen91 Nov 11, 2020
f7e2f27
test: update unit tests legend
rshen91 Nov 12, 2020
ec97027
Merge remote-tracking branch 'upstream/master' into legend-keyboard
rshen91 Nov 12, 2020
5b842fe
style: fix focus styling
rshen91 Nov 12, 2020
7753767
Merge remote-tracking branch 'upstream/master' into legend-keyboard
rshen91 Nov 12, 2020
bc14508
fix: add color name to aria label
rshen91 Nov 16, 2020
038f30c
fix: cleanup style and test
rshen91 Nov 16, 2020
e5a83e4
fix: add ownFocus to color story
rshen91 Nov 16, 2020
dc373e8
fix: add changes to label for isSeriesHidden
rshen91 Nov 16, 2020
cde7eb9
fix: add label to aria label
rshen91 Nov 16, 2020
07eadda
fix: add clearer aria label to color picker
rshen91 Nov 17, 2020
c78bfce
Merge remote-tracking branch 'upstream/master' into legend-keyboard
rshen91 Nov 17, 2020
f751a99
style: incorporate style changes in review
rshen91 Nov 17, 2020
e2f516a
Merge remote-tracking branch 'upstream/master' into legend-keyboard
rshen91 Nov 20, 2020
ef51a44
WIP
rshen91 Nov 23, 2020
a2cfae8
Merge remote-tracking branch 'upstream/master' into legend-keyboard
rshen91 Nov 24, 2020
a85b704
Merge remote-tracking branch 'upstream/master' into legend-keyboard
rshen91 Nov 25, 2020
5e29295
Merge remote-tracking branch 'upstream/master' into legend-keyboard
rshen91 Nov 25, 2020
35425e2
test: add puppeteer test for aria label and tabbing on legend items
rshen91 Nov 30, 2020
0538d65
Merge remote-tracking branch 'upstream/master' into legend-keyboard
rshen91 Nov 30, 2020
27c4826
test: add async test for tab and enter
rshen91 Nov 30, 2020
58a74d4
test: update vrts
rshen91 Nov 30, 2020
326cc37
refactor: update async test
rshen91 Nov 30, 2020
07fd6e2
test: add style changes and revert vrts
rshen91 Dec 1, 2020
92eb0e2
Merge remote-tracking branch 'upstream/master' into legend-keyboard
rshen91 Dec 2, 2020
ecc7797
feat: update aria label for isSeriesHidden
rshen91 Dec 2, 2020
48f01e7
test: euiring styling vrt update on tests
rshen91 Dec 2, 2020
fc8c562
test: flaky test update and second wait for legend test
rshen91 Dec 2, 2020
dd19e9d
test: update vrts
rshen91 Dec 2, 2020
d14a03a
test: add style consistency to test
rshen91 Dec 2, 2020
03ee240
test: add style test for pupeteer
rshen91 Dec 3, 2020
c260426
Merge remote-tracking branch 'upstream/master' into legend-keyboard
rshen91 Dec 3, 2020
3631426
test: add disable-animations to common and area stories
rshen91 Dec 4, 2020
64e99f8
Merge remote-tracking branch 'upstream/master' into legend-keyboard
rshen91 Dec 4, 2020
02a2555
test: add missing area vrts
rshen91 Dec 4, 2020
5bdb611
refactor: remove url parameter from disableAnimations
rshen91 Dec 6, 2020
8932129
Merge remote-tracking branch 'upstream/master' into legend-keyboard
rshen91 Dec 7, 2020
55f1628
style: remove old comments
rshen91 Dec 9, 2020
02a06fe
style: disable eslint in lines vs entire file
rshen91 Dec 9, 2020
a5acd93
refactor: pr feedback changes
rshen91 Dec 9, 2020
547f69d
Merge branch 'master' into legend-keyboard
rshen91 Dec 9, 2020
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
59 changes: 10 additions & 49 deletions .playground/playground.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,67 +38,28 @@

import React from 'react';

import {
AnnotationDomainTypes,
Axis,
BarSeries,
Chart,
LineAnnotation,
LineAnnotationDatum,
ScaleType,
Settings,
} from '../src';
import { Icon } from '../src/components/icons/icon';
import { Axis, BarSeries, Chart, ScaleType, Settings } from '../src';
import { Position } from '../src/utils/commons';
import { arrayKnobs } from '../stories/utils/knobs';

function generateAnnotationData(values: any[]): LineAnnotationDatum[] {
return values.map((value, index) => ({ dataValue: value, details: `detail-${index}` }));
}
const data = arrayKnobs('data values', [2.5, 7.2]);
const dataValues = generateAnnotationData(data);
import * as TestDatasets from '../src/utils/data_samples/test_dataset';

export class Playground extends React.Component {
render() {
return (
<div className="chart">
<Chart className="story-chart">
<Settings showLegend showLegendExtra />
<LineAnnotation
id="annotation_1"
domainType={AnnotationDomainTypes.XDomain}
dataValues={dataValues}
marker={<Icon type="alert" />}
/>
<LineAnnotation id="1" domainType={AnnotationDomainTypes.YDomain} dataValues={dataValues} />
<Axis id="horizontal" position={Position.Bottom} title="x-domain axis" />
<Axis id="left" title="y-domain axis left" position={Position.Left} />
<Axis id="right" title="y-domain axis right" position={Position.Right} />
<Settings showLegend showLegendExtra legendPosition={Position.Right} />
<Axis id="bottom" position={Position.Bottom} title="Bottom axis" showOverlappingTicks />
<Axis id="left2" title="Left axis" position={Position.Left} tickFormat={(d) => Number(d).toFixed(2)} />

<BarSeries
id="bars"
groupId="group1"
xScaleType={ScaleType.Linear}
yScaleType={ScaleType.Linear}
xAccessor="x"
yAccessors={['y']}
data={[
{ x: 0, y: 0 },
{ x: 1, y: 5 },
{ x: 3, y: 20 },
]}
/>
<BarSeries
id="bars1"
groupId="group2"
xScaleType={ScaleType.Linear}
yScaleType={ScaleType.Linear}
xAccessor="x"
yAccessors={['y']}
data={[
{ x: 0, y: 100 },
{ x: 1, y: 50 },
{ x: 3, y: 200 },
]}
yAccessors={['y1', 'y2']}
splitSeriesAccessors={['g1', 'g2']}
data={TestDatasets.BARCHART_2Y2G}
hideInLegend={false}
/>
</Chart>
</div>
Expand Down
1 change: 1 addition & 0 deletions src/chart_types/xy_chart/renderer/canvas/xy_chart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ class XYChartComponent extends React.Component<XYChartProps> {
width,
height,
}}
tabIndex={0}
myasonik marked this conversation as resolved.
Show resolved Hide resolved
/>
);
}
Expand Down
2 changes: 1 addition & 1 deletion src/components/__snapshots__/chart.test.tsx.snap
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`Chart should render the legend name test 1`] = `"<div class=\\"echChart\\" style=\\"width: 100px; height: 100px;\\"><div class=\\"echChartBackground\\" style=\\"background-color: transparent;\\"></div><div class=\\"echChartStatus\\" data-ech-render-complete=\\"true\\" data-ech-render-count=\\"1\\"></div><div class=\\"echChartResizer\\"></div><div class=\\"echLegend echLegend--right echLegend--debug\\"><div style=\\"width: 50px; max-width: 50px; margin-left: 0px; margin-right: 0px;\\" class=\\"echLegendListContainer\\"><ul style=\\"padding-top: 10px; padding-bottom: 10px;\\" class=\\"echLegendList\\"><li class=\\"echLegendItem echLegendItem--right\\" data-ech-series-name=\\"test\\"><div class=\\"echLegendItem__color\\" aria-label=\\"series color\\" title=\\"series color\\"><div><svg xmlns=\\"http://www.w3.org/2000/svg\\" width=\\"16\\" height=\\"16\\" class=\\"echIcon\\" color=\\"#1EA593\\" focusable=\\"false\\"><defs><circle id=\\"dot-a\\" cx=\\"8\\" cy=\\"8\\" r=\\"4\\"></circle></defs><g><use xlink:href=\\"#dot-a\\"></use></g></svg></div></div><div class=\\"echLegendItem__label echLegendItem__label--clickable\\" title=\\"test\\">test</div></li></ul></div></div><div class=\\"echContainer\\"><div class=\\"echChartPointerContainer\\" style=\\"cursor: default;\\"><div class=\\"echCrosshair\\"><div class=\\"echCrosshair__band\\" style=\\"top: -1px; left: -1px; width: 0px; height: 0px; background: rgb(245, 245, 245);\\"></div></div><canvas class=\\"echCanvasRenderer\\" width=\\"150\\" height=\\"200\\" style=\\"width: 150px; height: 200px;\\"></canvas><svg class=\\"echHighlighter\\"><defs><clipPath id=\\"echHighlighterClipPath__chart1\\"><rect x=\\"0\\" y=\\"0\\" width=\\"130\\" height=\\"180\\"></rect></clipPath></defs><g></g></svg></div></div></div>"`;
exports[`Chart should render the legend name test 1`] = `"<div class=\\"echChart\\" style=\\"width: 100px; height: 100px;\\"><div class=\\"echChartBackground\\" style=\\"background-color: transparent;\\"></div><div class=\\"echChartStatus\\" data-ech-render-complete=\\"true\\" data-ech-render-count=\\"1\\"></div><div class=\\"echChartResizer\\"></div><div class=\\"echLegend echLegend--right echLegend--debug\\"><div style=\\"width: 50px; max-width: 50px; margin-left: 0px; margin-right: 0px;\\" class=\\"echLegendListContainer\\"><ul style=\\"padding-top: 10px; padding-bottom: 10px;\\" class=\\"echLegendList\\" role=\\"listbox\\"><li class=\\"echLegendItem echLegendItem--right\\" data-ech-series-name=\\"test\\"><button type=\\"button\\" class=\\"echLegendItem__color\\" aria-label=\\"series color\\" title=\\"series color\\"><div><svg xmlns=\\"http://www.w3.org/2000/svg\\" width=\\"16\\" height=\\"16\\" class=\\"echIcon\\" color=\\"#1EA593\\" focusable=\\"false\\"><defs><circle id=\\"dot-a\\" cx=\\"8\\" cy=\\"8\\" r=\\"4\\"></circle></defs><g><use xlink:href=\\"#dot-a\\"></use></g></svg></div></button><button type=\\"button\\" class=\\"echLegendItem__label echLegendItem__label--clickable\\" title=\\"test \\" aria-label=\\"test \\">test</button></li></ul></div></div><div class=\\"echContainer\\"><div class=\\"echChartPointerContainer\\" style=\\"cursor: default;\\"><div class=\\"echCrosshair\\"><div class=\\"echCrosshair__band\\" style=\\"top: -1px; left: -1px; width: 0px; height: 0px; background: rgb(245, 245, 245);\\"></div></div><canvas class=\\"echCanvasRenderer\\" width=\\"150\\" height=\\"200\\" style=\\"width: 150px; height: 200px;\\" tabindex=\\"0\\"></canvas><svg class=\\"echHighlighter\\"><defs><clipPath id=\\"echHighlighterClipPath__chart1\\"><rect x=\\"0\\" y=\\"0\\" width=\\"130\\" height=\\"180\\"></rect></clipPath></defs><g></g></svg></div></div></div>"`;
6 changes: 3 additions & 3 deletions src/components/legend/__snapshots__/legend.test.tsx.snap

Large diffs are not rendered by default.

10 changes: 8 additions & 2 deletions src/components/legend/_legend.scss
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
grid-row-gap: $echLegendRowGap;
margin-top: $echLegendRowGap;
margin-bottom: $echLegendRowGap;

@include internetExplorerOnly {
display: flex;
flex-direction: row;
Expand Down Expand Up @@ -38,10 +37,17 @@
position: relative;
}

:focus {
box-shadow: inset 0 0 0 $euiSizeXS / 4 $euiFocusRingColor;
}

.echLegendListContainer {
@include euiYScrollWithShadows;
width: 100%;
overflow-y: auto;
overflow-x: hidden;
}

&:focus {
box-shadow: inset 0 0 0 $euiSizeXS / 4 $euiFocusRingColor;
Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks, @rshen91 for introducing this keyboard navigation. It's a very good improvement! 🎉

I tested this PR locally and I would suggest use our EUI variables and mixins to create the focus styles:

Suggested change
box-shadow: inset 0 0 0 $euiSizeXS / 4 $euiFocusRingColor;
@include euiFocusRing;
background-color: $euiFocusBackgroundColor;
border-radius: $euiBorderRadius / 2;

It will look like this:
Screenshot 2020-11-12 at 16 10 41

Screenshot 2020-11-12 at 16 18 06

I tested these for different examples like the Legend - Color Picker and it doesn't look good. It seems that the legends have different styles so the euiFocusRing doesn't surround the legend properly. Is it possible to fix this?

Screenshot 2020-11-12 at 16 11 41

Copy link
Collaborator

Choose a reason for hiding this comment

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

@miukimiu Would the hover state change at all?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thank you so much for the help- please see 5b842fe when you have a chance

Copy link
Contributor

Choose a reason for hiding this comment

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

@nickofthyme I don't think we need to change the hover state for now.

}
}
10 changes: 9 additions & 1 deletion src/components/legend/_legend_item.scss
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ $legendItemVerticalPadding: $echLegendRowGap / 2;
align-items: center;
width: 100%;

&:focus {
box-shadow: inset 0 0 0 $euiSizeXS / 4 $euiFocusRingColor;
}

&:not(&--hidden) {
.echLegendItem__color--changable {
cursor: pointer;
Expand Down Expand Up @@ -49,6 +53,10 @@ $legendItemVerticalPadding: $echLegendRowGap / 2;
@include euiFontSizeXS;
@include euiTextTruncate;
flex: 1 1 auto;
width: 100%;
text-align: left;
overflow-x: scroll;
overflow: hidden;

&--clickable {
&:hover {
Expand All @@ -61,9 +69,9 @@ $legendItemVerticalPadding: $echLegendRowGap / 2;
&__extra {
@include euiFontSizeXS;
text-align: right;
flex: 0 0 auto;
margin-left: $euiSizeXS;
font-feature-settings: 'tnum';
flex: 0 0 auto;

&--hidden {
display: none;
Expand Down
11 changes: 6 additions & 5 deletions src/components/legend/color.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@ export const Color = memo(
forwardRef<HTMLDivElement, ColorProps>(({ color, isSeriesHidden = false, hasColorPicker, onClick }, ref) => {
if (isSeriesHidden) {
return (
<div className="echLegendItem__color" aria-label="series hidden" title="series hidden">
<button type="button" className="echLegendItem__color" aria-label="series hidden" title="series hidden">
myasonik marked this conversation as resolved.
Show resolved Hide resolved
{/* changing the default viewBox for the eyeClosed icon to keep the same dimensions */}
<Icon type="eyeClosed" viewBox="-3 -3 22 22" />
</div>
</button>
);
}

Expand All @@ -49,16 +49,17 @@ export const Color = memo(
});

return (
<div
<button
type="button"
myasonik marked this conversation as resolved.
Show resolved Hide resolved
onClick={hasColorPicker ? onClick : undefined}
myasonik marked this conversation as resolved.
Show resolved Hide resolved
className={colorClasses}
aria-label="series color"
aria-label={hasColorPicker ? 'change series color' : 'series color'}
myasonik marked this conversation as resolved.
Show resolved Hide resolved
title={hasColorPicker ? 'change series color' : 'series color'}
>
<div ref={ref}>
<Icon type="dot" color={color} />
</div>
</div>
</button>
);
}),
);
Expand Down
2 changes: 1 addition & 1 deletion src/components/legend/extra.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export function renderExtra(extra: string | number, isSeriesHidden?: boolean) {
'echLegendItem__extra--hidden': isSeriesHidden,
});
return (
<div className={extraClassNames} title={`${extra}`}>
<div className={extraClassNames} title={`${extra}`} aria-label={`${extra}`}>
myasonik marked this conversation as resolved.
Show resolved Hide resolved
{extra}
</div>
);
Expand Down
24 changes: 21 additions & 3 deletions src/components/legend/label.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,37 @@ import React, { MouseEventHandler } from 'react';

interface LabelProps {
label: string;
extra: string | number | undefined;
onClick?: MouseEventHandler;
}
/**
* Label component used to display text in legend item
* @internal
*/
export function Label({ label, onClick }: LabelProps) {
export function Label({ label, extra, onClick }: LabelProps) {
const labelClassNames = classNames('echLegendItem__label', {
'echLegendItem__label--clickable': Boolean(onClick),
});
const labelWithExtra = getExtra(label, extra);
myasonik marked this conversation as resolved.
Show resolved Hide resolved
return (
<div className={labelClassNames} title={label} onClick={onClick}>
<button
type="button"
className={labelClassNames}
title={labelWithExtra}
onClick={onClick}
aria-label={labelWithExtra}
>
{label}
</div>
</button>
);
}

/**
* @internal
*/
function getExtra(label: string, extra: string | number | undefined) {
if (extra !== undefined) {
return `${label} ${extra}`;
}
return `${label}`;
}
2 changes: 1 addition & 1 deletion src/components/legend/legend.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ function LegendComponent(props: LegendStateProps & LegendDispatchProps) {
return (
<div className={legendClasses}>
<div style={legendContainerStyle} className="echLegendListContainer">
<ul style={legendListStyle} className="echLegendList">
<ul style={legendListStyle} className="echLegendList" role="listbox">
myasonik marked this conversation as resolved.
Show resolved Hide resolved
{items.map((item, index) => renderLegendItem(item, itemProps, items.length, index))}
</ul>
</div>
Expand Down
2 changes: 1 addition & 1 deletion src/components/legend/legend_item.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ export class LegendListItem extends Component<LegendItemProps, LegendItemState>
hasColorPicker={hasColorPicker}
onClick={this.handleColorClick(hasColorPicker)}
/>
<ItemLabel label={label} onClick={this.handleLabelClick(seriesIdentifier)} />
<ItemLabel label={label} onClick={this.handleLabelClick(seriesIdentifier)} extra={extra} />
{showExtra && extra != null && renderExtra(extra, isSeriesHidden)}
{Action && (
<div className="echLegendItem__action">
Expand Down
5 changes: 3 additions & 2 deletions stories/legend/11_legend_actions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,8 @@ const getAction = (hideActions: boolean, anchorPosition: PopoverAnchorPosition):
];

const Button = (
<div
<button
type="button"
style={{
display: 'flex',
justifyContent: 'center',
Expand All @@ -113,7 +114,7 @@ const getAction = (hideActions: boolean, anchorPosition: PopoverAnchorPosition):
onClick={() => setPopoverOpen(!popoverOpen)}
>
<EuiIcon size="s" type="pencil" />
</div>
</button>
);

return (
myasonik marked this conversation as resolved.
Show resolved Hide resolved
Expand Down