Skip to content

Commit

Permalink
fix(StructuredList): add aria table roles
Browse files Browse the repository at this point in the history
  • Loading branch information
dakahn committed Mar 13, 2021
1 parent eb81408 commit 70eba6e
Showing 1 changed file with 9 additions and 10 deletions.
19 changes: 9 additions & 10 deletions packages/react/src/components/StructuredList/StructuredList.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@
* LICENSE file in the root directory of this source tree.
*/

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

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

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

return (
<div className={classes} {...other} aria-label={ariaLabel}>
<div role="table" className={classes} {...other} aria-label={ariaLabel}>
{children}
</div>
);
Expand Down Expand Up @@ -74,7 +75,7 @@ export function StructuredListHead(props) {
const classes = classNames(`${prefix}--structured-list-thead`, className);

return (
<div className={classes} {...other}>
<div role="rowgroup" className={classes} {...other}>
{children}
</div>
);
Expand All @@ -92,16 +93,14 @@ StructuredListHead.propTypes = {
className: PropTypes.string,
};

const getInstanceId = setupGetInstanceId();

export function StructuredListBody(props) {
const { children, className, ...other } = props;
const classes = classNames(`${prefix}--structured-list-tbody`, className);
const { labelRows, setLabelRows } = useState(null);
const { rowSelected, setRowSelected } = useState(0);

return (
<div className={classes} {...other}>
<div className={classes} role="rowgroup" {...other}>
{children}
</div>
);
Expand Down Expand Up @@ -201,16 +200,16 @@ StructuredListRow.defaultProps = {
};

export function StructuredListInput(props) {
const { className, value, name, title, ...other } = props;
const uid = props.id || getInstanceId();
const { className, value, name, title, id, ...other } = props;
const classes = classNames(`${prefix}--structured-list-input`, className);
const instanceId = id || getInstanceId();

return (
<input
{...other}
type="radio"
tabIndex={-1}
id={uid}
id={instanceId}
className={classes}
value={value}
name={name}
Expand Down Expand Up @@ -271,7 +270,7 @@ export function StructuredListCell(props) {
});

return (
<div className={classes} {...other}>
<div className={classes} role={head ? 'columnheader' : 'cell'} {...other}>
{children}
</div>
);
Expand Down

0 comments on commit 70eba6e

Please sign in to comment.