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(StructuredList): Accessibility refactor #8172

Merged
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
6954ba0
fix(StructuredList): refactor instanceId
dakahn Mar 18, 2021
cb09d20
fix(StructuredList): convert to radio interaction, add focus state
dakahn Mar 23, 2021
1f46ed5
fix(StructuredList): hide radio input
dakahn Mar 23, 2021
f655b31
fix(StructuredList): remove label and tabIndex props on input
dakahn Mar 23, 2021
156cbc1
test(StructuredList): update tests, remove label tests
dakahn Mar 23, 2021
bd86cea
fix(StructuredList): style changes, add deprecation warning
dakahn Mar 24, 2021
909726a
fix(StructuredList): add context for row click handler
dakahn Mar 25, 2021
fb68deb
test(StructuredList): add specificity to classname testing
dakahn Mar 30, 2021
48ef999
fix(StructuredList): add clearer deprecation warning for defaultChecked
dakahn Mar 30, 2021
15310ad
Merge branch 'main' into 1937-improved-selection-a11y
dakahn Mar 30, 2021
fd90e92
fix(structuredList): updated style
andreancardona Mar 31, 2021
5af34a2
fix(structuredList): updated style again
andreancardona Mar 31, 2021
0487407
Merge branch 'main' of github.com:carbon-design-system/carbon into 19…
dakahn Apr 1, 2021
606c728
Update packages/react/src/components/StructuredList/StructuredList.js
dakahn Apr 1, 2021
c2184ea
Merge branch 'main' into 1937-improved-selection-a11y
dakahn Apr 1, 2021
2673889
fix(StructuredList): update render return to be in carbon style
dakahn Apr 1, 2021
7d835f4
Merge branch '1937-improved-selection-a11y' of github.com:dakahn/carb…
dakahn Apr 1, 2021
c151da7
Merge branch 'main' of github.com:carbon-design-system/carbon into 19…
dakahn Apr 6, 2021
84fa755
Merge branch 'main' of github.com:carbon-design-system/carbon into 19…
dakahn Apr 7, 2021
2cdf113
fix(StructuredList): move new work to /next
dakahn Apr 7, 2021
08ce487
fix(StructuredList): put changes behind feature flag
dakahn Apr 7, 2021
110e400
Merge branch 'main' of github.com:carbon-design-system/carbon into 19…
dakahn Apr 9, 2021
e6a9615
test(StructuredList): add old version tests
dakahn Apr 9, 2021
07eda0d
fix(StructuredList): update to Carbon naming convention
dakahn Apr 12, 2021
7770b66
test(StructuredList): update snapshots
dakahn Apr 12, 2021
12c3862
test(StructuredList): address merge conflicts
dakahn Apr 12, 2021
939bcfd
Merge branch 'main' of github.com:carbon-design-system/carbon into 19…
dakahn Apr 12, 2021
4d9c07c
Merge branch 'main' into 1937-improved-selection-a11y
dakahn Apr 13, 2021
182a935
Merge branch 'main' into 1937-improved-selection-a11y
andreancardona Apr 14, 2021
1789d5d
Merge branch 'main' into 1937-improved-selection-a11y
dakahn Apr 14, 2021
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 @@ -18,8 +18,8 @@
@include padding--data-structured-list;
}

.#{$prefix}--structured-list-input {
display: none;
.#{$prefix}--structured-list-row--focused-within {
@include focus-outline('outline');
}

.#{$prefix}--structured-list {
Expand Down Expand Up @@ -62,10 +62,6 @@
cursor: inherit;
}

.#{$prefix}--structured-list-row:focus:not(.#{$prefix}--structured-list-row--header-row) {
@include focus-outline('outline');
}

.#{$prefix}--structured-list--selection
.#{$prefix}--structured-list-row:hover:not(.#{$prefix}--structured-list-row--header-row)
> .#{$prefix}--structured-list-td,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4970,9 +4970,7 @@ Map {
"StructuredListRow" => Object {
"defaultProps": Object {
"head": false,
"label": false,
"onKeyDown": [Function],
"tabIndex": 0,
},
"propTypes": Object {
"children": Object {
Expand All @@ -4984,15 +4982,9 @@ Map {
"head": Object {
"type": "bool",
},
"label": Object {
"type": "bool",
},
"onKeyDown": Object {
"type": "func",
},
"tabIndex": Object {
"type": "number",
},
},
},
"StructuredListInput" => Object {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,16 +120,6 @@ describe('StructuredListRow', () => {
).toEqual(true);
});

it('should use <div> HTML by default (or when label prop is false)', () => {
const wrapperLabel = shallow(<StructuredListRow />);
expect(wrapperLabel.getElement().type).toEqual('div');
});

it('should use <label> HTML when label prop is true', () => {
const wrapperLabel = shallow(<StructuredListRow label />);
expect(wrapperLabel.getElement().type).toEqual('label');
});

it('Should accept other props from ...other', () => {
const wrapperProps = shallow(
<StructuredListRow title="title">hi</StructuredListRow>
Expand Down
79 changes: 41 additions & 38 deletions packages/react/src/components/StructuredList/StructuredList.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,14 @@
* LICENSE file in the root directory of this source tree.
*/

import React from 'react';
import React, { useState } from 'react';
import PropTypes from 'prop-types';
import classNames from 'classnames';
import { settings } from 'carbon-components';
import setupGetInstanceId from '../../tools/setupGetInstanceId';
import { useId } from '../../internal/useId';
import deprecate from '../../prop-types/deprecate';

const { prefix } = settings;
const getInstanceId = setupGetInstanceId();

export function StructuredListWrapper(props) {
const {
Expand All @@ -29,7 +28,7 @@ export function StructuredListWrapper(props) {
});

return (
<div role="table" className={classes} {...other} aria-label={ariaLabel}>
<div role="grid" className={classes} {...other} aria-label={ariaLabel}>
{children}
</div>
);
Expand Down Expand Up @@ -127,32 +126,38 @@ StructuredListBody.defaultProps = {
onKeyDown: () => {},
};

function useFocusWithin() {
dakahn marked this conversation as resolved.
Show resolved Hide resolved
const [hasFocusWithin, setHasFocusWithin] = useState(false);
return [hasFocusWithin, setHasFocusWithin];
}

export function StructuredListRow(props) {
const {
onKeyDown,
tabIndex,
children,
className,
head,
label,
...other
} = props;
const { onKeyDown, children, className, head, ...other } = props;
const [hasFocusWithin, setHasFocusWithin] = useFocusWithin();
dakahn marked this conversation as resolved.
Show resolved Hide resolved
const classes = classNames(`${prefix}--structured-list-row`, className, {
[`${prefix}--structured-list-row--header-row`]: head,
[`${prefix}--structured-list-row--focused-within`]: hasFocusWithin,
});

return label ? (
return head ? (
<div tabIndex={-1} role="row" {...other} className={classes}>
dakahn marked this conversation as resolved.
Show resolved Hide resolved
{children}
</div>
) : (
// eslint-disable-next-line jsx-a11y/no-noninteractive-element-interactions
<label
<div
{...other}
tabIndex={tabIndex}
role="row"
tabIndex={-1}
className={classes}
onFocus={() => {
setHasFocusWithin(true);
}}
onBlur={() => {
setHasFocusWithin(false);
}}
onKeyDown={onKeyDown}>
{children}
</label>
) : (
<div {...other} className={classes}>
{children}
</div>
);
}
Expand All @@ -173,41 +178,39 @@ StructuredListRow.propTypes = {
*/
head: PropTypes.bool,

/**
* Specify whether a `<label>` should be used
*/
label: PropTypes.bool,
dakahn marked this conversation as resolved.
Show resolved Hide resolved

/**
* Provide a handler that is invoked on the key down event for the control,
* if `<label>` is in use
*/
onKeyDown: PropTypes.func,

/**
* Specify the tab index of the container node, if `<label>` is in use
*/
tabIndex: PropTypes.number,
};

StructuredListRow.defaultProps = {
head: false,
label: false,
tabIndex: 0,
onKeyDown: () => {},
};

export function StructuredListInput(props) {
const { className, value, name, title, id, ...other } = props;
const classes = classNames(`${prefix}--structured-list-input`, className);
const instanceId = id || getInstanceId();
const defaultId = useId('structureListInput');
const {
className,
value,
name = `structuredListInput-${defaultId}`,
dakahn marked this conversation as resolved.
Show resolved Hide resolved
title,
id,
...other
} = props;
const classes = classNames(
`${prefix}--structured-list-input`,
`${prefix}--visually-hidden`,
className
);

return (
<input
{...other}
type="radio"
tabIndex={-1}
id={instanceId}
tabIndex={0}
id={id || defaultId}
className={classes}
value={value}
name={name}
Expand Down