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 all 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
218 changes: 138 additions & 80 deletions .playground/playground.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,91 +17,149 @@
* under the License.
*/

/*
* Licensed to Elasticsearch B.V. under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch B.V. licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

import React from 'react';

import {
AnnotationDomainTypes,
Axis,
BarSeries,
Chart,
LineAnnotation,
LineAnnotationDatum,
ScaleType,
Settings,
} from '../src';
import { Icon } from '../src/components/icons/icon';
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}` }));
interface Food {
label: string;
count: number;
actionLabel: string;
}
const data = arrayKnobs('data values', [2.5, 7.2]);
const dataValues = generateAnnotationData(data);

type Foods = Array<Food>;

type FoodArray = Array<string>;

export class Playground extends React.Component {
foods: Foods = [
{ label: 'pie', count: 2, actionLabel: 'tab' },
{ label: 'asparagus', count: 5, actionLabel: 'tab' },
{ label: 'brownies', count: 0, actionLabel: 'enter' },
{ label: 'popsicles', count: 3, actionLabel: 'enter' },
];

foodsAsAnArray: FoodArray = ['tab', 'tab', 'tab', 'enter'];

getFoodsArrayAction = (foodsArray: FoodArray) => {
for (let i = 0; i < foodsArray.length; i++) {
if (foodsArray[i] === 'tab') {
// alert('tab!');
} else if (foodsArray[i] === 'enter') {
// alert('enter!');
}
}
};

getFoodAction = (foodLabel: Food[keyof Food]) => {
// eslint-disable-next-line array-callback-return
return this.foods.map(({ label, count, actionLabel }) => {
if (foodLabel === label && actionLabel === 'tab') {
let c = 0;
while (c < count) {
// alert(`${label} Tab!`);
c++;
}
} else if (foodLabel === label && actionLabel === 'enter') {
let c = 0;
while (c < count) {
// alert(`${label} Enter!`);
c++;
}
}
});
};

makingFood = (ms: number, food: string) => {
return new Promise((resolve) => {
setTimeout(() => {
// console.log(`resolving the promise ${food}`, new Date());
resolve(`done with ${food}`);
}, ms);
// console.log(`starting the promise ${food}`, new Date());
});
};

getNumberOfFood = (food: any) => {
return this.makingFood(1000, food).then(() => this.getFoodAction(food));
};

getNumberOfFoodArray = () => {
return this.makingFood(1000, 'apple').then(() => this.getFoodsArrayAction(this.foodsAsAnArray));
};

getAsyncNumberOfFoodArray = async () => {
// const result = await this.makingFood(2000).then(() => this.getFoodsArrayAction(this.foodsAsAnArray));
// alert(result);
};

// forLoop = async () => {
// alert('start');
// for (let index = 0; index < this.foods.length; index++) {
// const foodLabel = this.foods[index].label;
// const numFood = await this.getFoodNumber(foodLabel);
// alert(numFood);
// }
// const foodsPromiseArray = this.foods.map(async (foodObject) => {
// for (let i = 0; i < foodObject.length; i++) {
// const numFoodAction = foodObject[i].actionLabel;
// if (numFoodAction === 'enter') {
// alert ('Enter!');
// } else if (numFoodAction === 'tab') {
// alert('tab!');
// }
// }
// });
// const numberOfFoods = await Promise.all(foodsPromiseArray);
// alert(numberOfFoods);
// alert('End');
// };

// getFoodArray =
// async() => {
// console.log(await this.makingFood(1000, 'apricot'));
// console.log(await this.makingFood(50, 'apple'));
// const foodTimeArray = [
// { ms: 1000, food: 'a', count: 2 },
// { ms: 50, food: 'b', count: 1 },
// { ms: 500, food: 'c', count: 3 },
// ];

// for (let i = 0; i < foodTimeArray.length; i++) {
// void this.makingFood(foodTimeArray[i].ms, foodTimeArray[i].food);
// }

// const foodMap = foodTimeArray.map(({ ms, food }) => {
// return this.makingFood(ms, food);
// });

// console.log('before the promise');
// for (const i of foodTimeArray) {
// const j = 0;
// while (j < i.count) {
// await this.makingFood(i.ms, i.food);
// j++;
// }
// }

// await Promise.all();
// console.log('after the promise');
// };

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} />
<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 },
]}
/>
</Chart>
</div>
);
// console.log(this.makingFood(1000, 'apricot'));
// console.log(this.makingFood(50, 'apple'));
// void this.getFoodArray();

return null;
// <>
// <div className="page" style={{ width: 5000, height: 5000, backgroundColor: 'yellow' }}>
// <div id="root" style={{ backgroundColor: 'blueviolet' }}>
// {/* <div>{this.foods.map(({ label }) => this.getNumberOfFood(label))}</div> */}
// {/* <div>{alert(this.makingFood(50000).then(this.getFoodsArrayAction(this.foodsAsAnArray)))}</div> */}
// {/* <div>{alert(this.getNumberOfFoodArray())}</div> */}
// {/* <div>{alert(this.getAsyncNumberOfFoodArray())}</div> */}
// <div>{this.makingFood(50)}</div>
// </div>
// </div>
// </>
}
}
13 changes: 13 additions & 0 deletions .storybook/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,19 @@ html {
position: relative;
box-sizing: border-box;
background-color: blanchedalmond;

&.disable-animations {
*,
*::after,
*::before {
transition-delay: 0s !important;
transition-duration: 0s !important;
animation-delay: -0.0001s !important;
animation-duration: 0s !important;
animation-play-state: paused !important;
caret-color: transparent !important;
}
}
}

#story-root + div table {
Expand Down
80 changes: 77 additions & 3 deletions integration/page_objects/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,13 @@ interface ElementBBox {
height: number;
}

interface KeyboardKey {
key: string;
count: number;
}

type KeyboardKeys = Array<KeyboardKey>;

/**
* Used to get postion from any value of cursor position
*
Expand Down Expand Up @@ -211,6 +218,15 @@ class CommonPage {
return buffer;
}

/**
* Move mouse
* @param mousePosition
* @param selector
*/
async moveMouse(x: number, y: number) {
await page.mouse.move(x, y);
}

/**
* Move mouse relative to element
*
Expand All @@ -220,7 +236,7 @@ class CommonPage {
async moveMouseRelativeToDOMElement(mousePosition: MousePosition, selector: string) {
const element = await this.getBoundingClientRect(selector);
const { x, y } = getCursorPosition(mousePosition, element);
await page.mouse.move(x, y);
await this.moveMouse(x, y);
}

/**
Expand All @@ -245,10 +261,10 @@ class CommonPage {
const element = await this.getBoundingClientRect(selector);
const { x: x0, y: y0 } = getCursorPosition(start, element);
const { x: x1, y: y1 } = getCursorPosition(end, element);
await page.mouse.move(x0, y0);
await this.moveMouse(x0, y0);
await page.mouse.down();
await page.waitFor(DRAG_DETECTION_TIMEOUT);
await page.mouse.move(x1, y1);
await this.moveMouse(x1, y1);
}

/**
Expand All @@ -261,6 +277,30 @@ class CommonPage {
await page.mouse.up();
}

/**
* Press keyboard keys
* @param count
* @param key
*/
// eslint-disable-next-line class-methods-use-this
async pressKey(key: string, count: number) {
if (key === 'tab') {
let i = 0;
while (i < count) {
// eslint-disable-next-line eslint-comments/disable-enable-pair
/* eslint-disable no-await-in-loop */
await page.keyboard.press('Tab');
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
await page.keyboard.press('Tab');
// eslint-disable-next-line no-await-in-loop
await page.keyboard.press('Tab');

Copy link
Contributor Author

Choose a reason for hiding this comment

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

changed in a5acd93

i++;
}
} else if (key === 'enter') {
let i = 0;
while (i < count) {
await page.keyboard.press('Enter');
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
await page.keyboard.press('Enter');
// eslint-disable-next-line no-await-in-loop
await page.keyboard.press('Enter');

i++;
}
}
}

/**
* Drag and drop mouse relative to element
*
Expand Down Expand Up @@ -341,6 +381,34 @@ class CommonPage {
});
}

/**
* Expect a chart given a url from storybook with keyboard events
* @param url
* @param keyboardEvents
* @param options
*/
async expectChartWithKeyboardEventsAtUrlToMatchScreenshot(
url: string,
keyboardEvents: KeyboardKeys,
options?: Omit<ScreenshotElementAtUrlOptions, 'action'>,
) {
const action = async () => {
await this.disableAnimations();
// click to focus within the chart
await this.clickMouseRelativeToDOMElement({ top: 0, left: 0 }, this.chartSelector);
// eslint-disable-next-line no-restricted-syntax
for (const actions of keyboardEvents) {
await this.pressKey(actions.key, actions.count);
}
await this.moveMouseRelativeToDOMElement({ top: 0, left: 0 }, this.chartSelector);
};

await this.expectChartAtUrlToMatchScreenshot(url, {
...options,
action,
});
}

/**
* Expect a chart given a url from storybook with mouse move
*
Expand Down Expand Up @@ -383,6 +451,12 @@ class CommonPage {
});
}

async disableAnimations() {
await page.evaluate(() => {
document.querySelector('#story-root')!.classList.add('disable-animations');
});
}

/**
* Wait for an element to be on the DOM
*
Expand Down
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading