Skip to content

Commit

Permalink
fix(TableSelectionCell): Radios should not change selection on focus (#…
Browse files Browse the repository at this point in the history
…26283)

* fix(TableSelectionCell): Radios should not change selection on focus

While native radios change selection on focus, it can be a bad
experience for keyboard users on larger widgets. If an author wants to
perform an action on row select, it won't force a keyboard user to
perform that action for every row between the one that they're on and
the one that they want.

Fixes #26196

* update tests

* changefile
  • Loading branch information
ling1726 authored Jan 11, 2023
1 parent ffa133f commit ac636e8
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "prerelease",
"comment": "fix(TableSelectionCell): Radios should not change selection on focus",
"packageName": "@fluentui/react-table",
"email": "[email protected]",
"dependentChangeType": "patch"
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import * as React from 'react';
import { render } from '@testing-library/react';
import { resetIdsForTests } from '@fluentui/react-utilities';
import { TableSelectionCell } from './TableSelectionCell';
import { isConformant } from '../../testing/isConformant';
import { TableSelectionCellProps } from './TableSelectionCell.types';
Expand All @@ -10,6 +11,7 @@ const tr = document.createElement('tr');
describe('TableSelectionCell', () => {
beforeEach(() => {
document.body.appendChild(tr);
resetIdsForTests();
});

isConformant({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ exports[`TableSelectionCell renders a default state 1`] = `
>
<input
class="fui-Checkbox__input"
id="checkbox-9"
id="checkbox-2"
type="checkbox"
/>
<div
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as React from 'react';
import { resolveShorthand } from '@fluentui/react-utilities';
import { resolveShorthand, useId } from '@fluentui/react-utilities';
import { Checkbox } from '@fluentui/react-checkbox';
import { Radio } from '@fluentui/react-radio';
import type { TableSelectionCellProps, TableSelectionCellState } from './TableSelectionCell.types';
Expand Down Expand Up @@ -36,7 +36,7 @@ export const useTableSelectionCell_unstable = (
}),
radioIndicator: resolveShorthand(props.radioIndicator, {
required: type === 'radio',
defaultProps: { checked: !!checked },
defaultProps: { checked: !!checked, input: { name: useId('table-selection-radio') } },
}),
type,
checked,
Expand Down

0 comments on commit ac636e8

Please sign in to comment.