Skip to content

Commit

Permalink
fix(Datagrid): sortable column focus issue (carbon-design-system#5853)
Browse files Browse the repository at this point in the history
  • Loading branch information
anamikaanu96 authored Aug 16, 2024
1 parent 1d8640f commit d679559
Showing 1 changed file with 10 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,14 @@ const useSortableColumns = (hooks: Hooks) => {
}
return <ArrowsVertical {...iconProps} />;
};

const handleKey = (e, columnId) => {
const { key } = e;
if (key === 'Enter') {
setTimeout(() => document.getElementById(columnId)?.focus(), 0);
}
};

const Header = (headerProp) =>
column.disableSortBy === true ||
column.id === 'datagridSelection' ||
Expand Down Expand Up @@ -153,6 +161,7 @@ const useSortableColumns = (hooks: Hooks) => {
</>
);
}}
id={column?.id}
className={cx(
`${carbon.prefix}--table-sort ${blockClass}--table-sort`,
{
Expand All @@ -162,6 +171,7 @@ const useSortableColumns = (hooks: Hooks) => {
headerProp?.column.isSortedDesc === false,
}
)}
onKeyDown={(event) => handleKey(event, column.id)}
>
{column.Header}
</Button>
Expand Down

0 comments on commit d679559

Please sign in to comment.