Skip to content

Commit

Permalink
feat: exposed tabIndex to Table component (#17907)
Browse files Browse the repository at this point in the history
* feat: exposed tabIndex to Table component

* test: fixed tests

* Update packages/react/src/components/DataTable/Table.tsx

Co-authored-by: Alison Joseph <[email protected]>

* fix: reset hard

---------

Co-authored-by: Alison Joseph <[email protected]>
Co-authored-by: Riddhi Bansal <[email protected]>
  • Loading branch information
3 people authored Nov 5, 2024
1 parent 32bd13e commit a87e522
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
6 changes: 6 additions & 0 deletions packages/react/__tests__/__snapshots__/PublicAPI-test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -1906,6 +1906,9 @@ Map {
"stickyHeader": Object {
"type": "bool",
},
"tabIndex": Object {
"type": "number",
},
"useStaticWidth": Object {
"type": "bool",
},
Expand Down Expand Up @@ -7949,6 +7952,9 @@ Map {
"stickyHeader": Object {
"type": "bool",
},
"tabIndex": Object {
"type": "number",
},
"useStaticWidth": Object {
"type": "bool",
},
Expand Down
13 changes: 12 additions & 1 deletion packages/react/src/components/DataTable/Table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,11 @@ interface TableProps {
* `true` to add useZebraStyles striping.
*/
useZebraStyles?: boolean;

/**
* Specify the table tabIndex
*/
tabIndex?: number;
}

const isElementWrappingContent = (
Expand Down Expand Up @@ -108,6 +113,7 @@ export const Table = ({
stickyHeader,
overflowMenuOnHover = true,
experimentalAutoAlign = false,
tabIndex,
...other
}: PropsWithChildren<TableProps>) => {
const { titleId, descriptionId } = useContext(TableContext);
Expand Down Expand Up @@ -226,7 +232,7 @@ export const Table = ({
<div
className={`${prefix}--data-table-content`}
// eslint-disable-next-line jsx-a11y/no-noninteractive-tabindex
tabIndex={isScrollable ? 0 : undefined}>
tabIndex={tabIndex ?? (isScrollable ? 0 : undefined)}>
<table
aria-labelledby={titleId}
aria-describedby={descriptionId}
Expand Down Expand Up @@ -287,6 +293,11 @@ Table.propTypes = {
* `true` to add useZebraStyles striping.
*/
useZebraStyles: PropTypes.bool,

/**
* Specify the table tabIndex
*/
tabIndex: PropTypes.number,
};

export default Table;

0 comments on commit a87e522

Please sign in to comment.