Skip to content

Commit

Permalink
feat: Allow to disable keyboard navigation on Table (#3892)
Browse files Browse the repository at this point in the history
* feat: Allow to disable keyboard navigation on `Table`

* Create many-rabbits-run.md

* lint
  • Loading branch information
sebald committed Apr 30, 2024
1 parent 4ac7cc6 commit 3f02ea1
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 1 deletion.
6 changes: 6 additions & 0 deletions .changeset/many-rabbits-run.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@marigold/docs": minor
"@marigold/components": minor
---

feat: Allow to disable keyboard navigation on `Table`
7 changes: 7 additions & 0 deletions docs/content/components/collection/table/table.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,13 @@ import { Table } from '@marigold/components';
description: 'Handler that is called when the sort direction changes.',
default: 'none',
},
{
property: 'disableKeyboardNavigation',
type: 'boolean',
description:
'Disable keyboard navigation. Use if you have input fields in your table. Be aware that this is bad for accessibility.',
default: 'false',
},
]}
/>

Expand Down
6 changes: 5 additions & 1 deletion packages/components/src/Table/Table.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -716,7 +716,11 @@ export const InputTable: Story = {

return (
<Stack space={3}>
<Table aria-label="Example dynamic collection table" {...args}>
<Table
aria-label="Example dynamic collection table"
disableKeyboardNavigation
{...args}
>
<Table.Header columns={columns}>
{column => <Table.Column>{column.name}</Table.Column>}
</Table.Header>
Expand Down
11 changes: 11 additions & 0 deletions packages/components/src/Table/Table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ export interface TableProps
size?: string;
stretch?: boolean;
stickyHeader?: boolean;
disableKeyboardNavigation?: boolean;
}

// Table Component
Expand All @@ -47,6 +48,7 @@ export const Table: Table = ({
size,
stretch,
selectionMode = 'none',
disableKeyboardNavigation = false,
stickyHeader,
...props
}: TableProps) => {
Expand All @@ -60,6 +62,15 @@ export const Table: Table = ({
// TODO: It this necessary?
props.selectionBehavior !== 'replace',
});

/**
* Behavior is a bit flacky with the table when using a keyboard
* so we test here for undefined here to be save.
*/
if (disableKeyboardNavigation !== undefined) {
state.isKeyboardNavigationDisabled = disableKeyboardNavigation;
}

const { gridProps } = useTable(props, state, tableRef);
const classNames = useClassNames({
component: 'Table',
Expand Down
1 change: 1 addition & 0 deletions packages/components/src/Table/TableCell.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ export const TableCell = ({ cell, align = 'left' }: TableCellProps) => {

const { focusProps, isFocusVisible } = useFocusRing();
const stateProps = useStateProps({ disabled, focusVisible: isFocusVisible });

return (
<td
ref={ref}
Expand Down

0 comments on commit 3f02ea1

Please sign in to comment.