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

Feature/highlight a11y violation on component #6218

Merged
Show file tree
Hide file tree
Changes from 40 commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
09e4d51
Added toggle button that highlight a11y rules based on type
CodeByAlex Mar 14, 2019
cf21ec3
Added toggle styling
CodeByAlex Mar 15, 2019
175a241
Merge pull request #1 from storybooks/next
CodeByAlex Mar 15, 2019
795a68e
Merge branch 'next' into feature/highlight-a11y-violation-on-component
CodeByAlex Mar 15, 2019
ef4c000
added enum usage for rule types in a11y
CodeByAlex Mar 15, 2019
f23e53e
formatted and pulled toggle component into its own file
CodeByAlex Mar 15, 2019
47b4a6e
added functionality that allows the Highlight Toggle to highlight mor…
CodeByAlex Mar 16, 2019
9f5c115
added redux store for smooth communication between toggle components
CodeByAlex Mar 17, 2019
965be3e
added redux store for smooth communication between toggle components
CodeByAlex Mar 17, 2019
46d5210
added map clearing logic
CodeByAlex Mar 18, 2019
f6aa867
fixed syncing issue between parent and child toggles
CodeByAlex Mar 18, 2019
7d2e962
fixed failing scenario: If parent is not set to true but some sub tog…
CodeByAlex Mar 19, 2019
410e9be
Cleaned up HighlightToggle.tsx
CodeByAlex Mar 19, 2019
d187b22
added global tab toggle
CodeByAlex Mar 19, 2019
db9b93a
Set key to type:item-id to fix the unique id issue with the already p…
CodeByAlex Mar 19, 2019
904565b
Replaced switches with checkboxes, moved "highlight results" checkbox…
CodeByAlex Mar 21, 2019
efea3c2
updated comment
CodeByAlex Mar 21, 2019
178082f
update yarn.lock to that in master
CodeByAlex Mar 21, 2019
d2149fd
update yarn.lock to that in master
CodeByAlex Mar 21, 2019
a62a2eb
Merge branch 'feature/highlight-a11y-violation-on-component' of https…
CodeByAlex Mar 21, 2019
f3a077b
master lock add
CodeByAlex Mar 21, 2019
858324a
removing lock file from PR
CodeByAlex Mar 21, 2019
c6730eb
Merge branch 'next' of https://github.com/storybooks/storybook into f…
CodeByAlex Mar 23, 2019
8a48a96
fixed failing tests
CodeByAlex Mar 23, 2019
618d7c7
fixed failing test for a11y
CodeByAlex Mar 23, 2019
1756687
commit snap
CodeByAlex Mar 23, 2019
1ab87ef
added logger to cra config
CodeByAlex Mar 23, 2019
325a104
used variables from theme for highlight colors
CodeByAlex Mar 24, 2019
16dd11e
cleaned up a11y code relating to the highlight toggle
CodeByAlex Mar 24, 2019
df3b4d3
added snap
CodeByAlex Mar 24, 2019
9b811e6
added basic tests for highlight toggle component
CodeByAlex Mar 24, 2019
a1f4fa1
removed rule type from redux store
CodeByAlex Mar 24, 2019
19f147a
renamed HighlightText styled component to HighlightToggleElement
CodeByAlex Mar 24, 2019
5572d24
Merge branch 'next' into feature/highlight-a11y-violation-on-component
CodeByAlex Mar 24, 2019
c0ce663
remove previously added client-logger from package json
CodeByAlex Mar 24, 2019
eb4b33e
uncapitalized "r" in Results
CodeByAlex Mar 24, 2019
d587cf8
VA centered the global highlight results checkbox and label
CodeByAlex Mar 24, 2019
5bff2ba
Added bg color change on rule hover underline underneath rule, and al…
CodeByAlex Mar 24, 2019
51a26d0
pulled global toggle label to the left side of the checkbox
CodeByAlex Mar 24, 2019
1d90bd6
Styling/theming tweaks, Typescript lint
domyen Mar 24, 2019
abe4e8e
adding updated snap
CodeByAlex Mar 25, 2019
c2ca7b3
removed unnecessary spaces
CodeByAlex Mar 25, 2019
a4b782f
Merge branch 'next' into pr/CodeByAlex/6218
ndelangen Mar 25, 2019
be43ad8
Fixed failing snapshots
CodeByAlex Mar 25, 2019
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
5 changes: 4 additions & 1 deletion addons/a11y/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
"@storybook/components": "5.1.0-alpha.13",
"@storybook/core-events": "5.1.0-alpha.13",
"@storybook/theming": "5.1.0-alpha.13",
"@types/react-redux": "^7.0.3",
"axe-core": "^3.2.2",
"common-tags": "^1.8.0",
"core-js": "^2.6.5",
Expand All @@ -41,7 +42,9 @@
"util-deprecate": "^1.0.2"
},
"devDependencies": {
"@types/common-tags": "^1.8.0"
"@types/common-tags": "^1.8.0",
"react-redux": "^6.0.1",
"redux": "^4.0.1"
},
"publishConfig": {
"access": "public"
Expand Down
108 changes: 67 additions & 41 deletions addons/a11y/src/components/A11YPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,15 @@ import { Tabs } from './Tabs';
import { EVENTS } from '../constants';
import { API } from '@storybook/api';

import { Provider } from 'react-redux';
import store, { clearElements } from '../redux-config';

export enum RuleType {
VIOLATION,
PASS,
INCOMPLETION,
}

const Icon = styled(Icons)(
{
height: '12px',
Expand Down Expand Up @@ -81,13 +90,14 @@ export class A11YPanel extends Component<A11YPanelProps, A11YPanelState> {
const { active } = this.props;

if (!prevProps.active && active) {
// removes all elements from the redux map in store from the previous panel
store.dispatch(clearElements(null));
this.request();
}
}

componentWillUnmount() {
const { api } = this.props;

api.off(STORY_RENDERED, this.request);
api.off(EVENTS.RESULT, this.onUpdate);
}
Expand Down Expand Up @@ -151,46 +161,62 @@ export class A11YPanel extends Component<A11YPanelProps, A11YPanelState> {

return active ? (
<Fragment>
{status === 'running' ? (
<Loader />
) : (
<ScrollArea vertical horizontal>
<Tabs
key="tabs"
tabs={[
{
label: <Violations>{violations.length} Violations</Violations>,
panel: (
<Report
name="violations"
passes={false}
items={violations}
empty="No a11y violations found."
/>
),
},
{
label: <Passes>{passes.length} Passes</Passes>,
panel: (
<Report name={'passes'} passes items={passes} empty="No a11y check passed." />
),
},
{
label: <Incomplete>{incomplete.length} Incomplete</Incomplete>,
panel: (
<Report
name="incomplete"
passes={false}
items={incomplete}
empty="No a11y incomplete found."
/>
),
},
]}
/>
</ScrollArea>
)}
<ActionBar key="actionbar" actionItems={[{ title: actionTitle, onClick: this.request }]} />
<Provider store={store}>
{status === 'running' ? (
<Loader />
) : (
<ScrollArea vertical horizontal>
<Tabs
key="tabs"
tabs={[
{
label: <Violations>{violations.length} Violations</Violations>,
panel: (
<Report
passes={false}
items={violations}
type={RuleType.VIOLATION}
empty="No a11y violations found."
/>
),
items: violations,
type: RuleType.VIOLATION,
},
{
label: <Passes>{passes.length} Passes</Passes>,
panel: (
<Report
passes
items={passes}
type={RuleType.PASS}
empty="No a11y check passed."
/>
),
items: passes,
type: RuleType.PASS,
},
{
label: <Incomplete>{incomplete.length} Incomplete</Incomplete>,
panel: (
<Report
passes={false}
items={incomplete}
type={RuleType.INCOMPLETION}
empty="No a11y incomplete found."
/>
),
items: incomplete,
type: RuleType.INCOMPLETION,
},
]}
/>
</ScrollArea>
)}
<ActionBar
key="actionbar"
actionItems={[{ title: actionTitle, onClick: this.request }]}
/>
</Provider>
</Fragment>
) : null;
}
Expand Down
36 changes: 27 additions & 9 deletions addons/a11y/src/components/Report/Elements.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,31 +4,48 @@ import { styled } from '@storybook/theming';

import { NodeResult } from 'axe-core';
import { Rules } from './Rules';
import { RuleType } from '../A11YPanel';
import HighlightToggle from './HighlightToggle';

const Item = styled.li({
fontWeight: 600,
});
const ItemTitle = styled.span({
borderBottom: '1px solid rgb(130, 130, 130)',

const ItemTitle = styled.span(({ theme }) => ({
borderBottom: `1px solid ${theme.appBorderColor}`,
width: '100%',
display: 'inline-block',
paddingBottom: '4px',
marginBottom: '4px',
paddingBottom: '6px',
marginBottom: '6px',
}));

const HighlightToggleElement = styled.span({
fontWeight: 'normal',
float: 'right',
paddingRight: '15px',
input: { margin: 0, },
});

interface ElementProps {
element: NodeResult;
passes: boolean;
type: RuleType;
}

const Element: FunctionComponent<ElementProps> = ({ element, passes }) => {
const Element: FunctionComponent<ElementProps> = ({ element, passes, type }) => {
const { any, all, none } = element;

const rules = [...any, ...all, ...none];
const highlightToggleId = `${type}-${element.target[0]}`;
const highlightLabel = `Highlight`;

return (
<Item>
<ItemTitle>{element.target[0]}</ItemTitle>
<ItemTitle>
{element.target[0]}
<HighlightToggleElement>
<HighlightToggle toggleId={highlightToggleId} type={type} elementsToHighlight={[element]} label={highlightLabel} />
</HighlightToggleElement>
</ItemTitle>
<Rules rules={rules} passes={passes} />
</Item>
);
Expand All @@ -37,12 +54,13 @@ const Element: FunctionComponent<ElementProps> = ({ element, passes }) => {
interface ElementsProps {
elements: NodeResult[];
passes: boolean;
type: RuleType;
}

export const Elements: FunctionComponent<ElementsProps> = ({ elements, passes }) => (
export const Elements: FunctionComponent<ElementsProps> = ({ elements, passes, type }) => (
<ol>
{elements.map((element, index) => (
<Element passes={passes} element={element} key={index} />
<Element passes={passes} element={element} key={index} type={type} />
))}
</ol>
);
40 changes: 40 additions & 0 deletions addons/a11y/src/components/Report/HighlightToggle.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import React from 'react';
import { mount } from 'enzyme';
import { Provider } from 'react-redux';
import { ThemeProvider, themes, convert } from '@storybook/theming';
import HighlightToggle from './HighlightToggle.tsx';
import store from '../../redux-config.tsx';

function ThemedHighlightToggle(props) {
return (
<ThemeProvider theme={convert(themes.normal)}>
<HighlightToggle {...props} />
</ThemeProvider>
);
}

describe('HighlightToggle component', () => {
test('should render', () => {
// given
const wrapper = mount(
<Provider store={store}>
<ThemedHighlightToggle />
</Provider>
);

// then
expect(wrapper.exists()).toBe(true);
});

test('should match snapshot', () => {
// given
const wrapper = mount(
<Provider store={store}>
<ThemedHighlightToggle />
</Provider>
);

// then
expect(wrapper).toMatchSnapshot();
});
});
Loading