Skip to content

Commit a434200

Browse files
authored
fix(DataGrid): single-select radio input should be fully hidden, not disabled (microsoft#35103)
1 parent d1c29c3 commit a434200

File tree

6 files changed

+25
-40
lines changed

6 files changed

+25
-40
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"type": "patch",
3+
"comment": "fix: single-select radio input should be fully hidden, not disabled",
4+
"packageName": "@fluentui/react-table",
5+
"email": "[email protected]",
6+
"dependentChangeType": "patch"
7+
}

packages/react-components/react-table/library/src/components/DataGridRow/DataGridRow.test.tsx

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -183,20 +183,6 @@ describe('DataGridRow', () => {
183183
expect(toggleRow).toHaveBeenCalledTimes(0);
184184
});
185185

186-
it('should disable selection cell input if the row is in a header and the selection mode is singe', () => {
187-
const toggleRow = jest.fn();
188-
const ctx = mockDataGridContext({ selectableRows: true }, { selection: { toggleRow, selectionMode: 'single' } });
189-
const { container } = render(
190-
<DataGridHeader>
191-
<DataGridContextProvider value={ctx}>
192-
<DataGridRow>{() => <div />}</DataGridRow>
193-
</DataGridContextProvider>
194-
</DataGridHeader>,
195-
);
196-
197-
expect(container.querySelector("input[type='radio']")?.hasAttribute('disabled')).toBe(true);
198-
});
199-
200186
it('should render aria-selected=true if row is selected', () => {
201187
const isRowSelected = () => true;
202188
const ctx = mockDataGridContext({ selectableRows: true }, { selection: { isRowSelected } });

packages/react-components/react-table/library/src/components/DataGridRow/useDataGridRow.tsx

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -79,11 +79,6 @@ export const useDataGridRow_unstable = (props: DataGridRowProps, ref: React.Ref<
7979
selectionCell: slot.optional(props.selectionCell, {
8080
renderByDefault: selectable,
8181
elementType: DataGridSelectionCell,
82-
defaultProps: {
83-
radioIndicator: {
84-
disabled: isHeader,
85-
},
86-
},
8782
}),
8883
renderCell: props.children,
8984
columnDefs,

packages/react-components/react-table/library/src/components/DataGridRow/useDataGridRowStyles.styles.ts

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import { createCustomFocusIndicatorStyle } from '@fluentui/react-tabster';
33
import type { DataGridRowSlots, DataGridRowState } from './DataGridRow.types';
44
import type { SlotClassNames } from '@fluentui/react-utilities';
55
import { useTableRowStyles_unstable } from '../TableRow/useTableRowStyles.styles';
6-
import { useIsInTableHeader } from '../../contexts/tableHeaderContext';
76
import { useDataGridContext_unstable } from '../../contexts/dataGridContext';
87
import { tableSelectionCellClassNames } from '../TableSelectionCell/useTableSelectionCellStyles.styles';
98

@@ -13,23 +12,6 @@ export const dataGridRowClassNames: SlotClassNames<DataGridRowSlots> = {
1312
};
1413

1514
const useStyles = makeStyles({
16-
singleSelectHeader: {
17-
...createCustomFocusIndicatorStyle(
18-
{
19-
[`& .${tableSelectionCellClassNames.root}`]: {
20-
opacity: 0,
21-
},
22-
},
23-
{ selector: 'focus-within' },
24-
),
25-
26-
':hover': {
27-
[`& .${tableSelectionCellClassNames.root}`]: {
28-
opacity: 0,
29-
},
30-
},
31-
},
32-
3315
subtleSelection: {
3416
...createCustomFocusIndicatorStyle(
3517
{
@@ -54,8 +36,6 @@ const useStyles = makeStyles({
5436
export const useDataGridRowStyles_unstable = (state: DataGridRowState): DataGridRowState => {
5537
'use no memo';
5638

57-
const isHeader = useIsInTableHeader();
58-
const isSingleSelect = useDataGridContext_unstable(ctx => ctx.selection.selectionMode === 'single');
5939
const isSubtle = useDataGridContext_unstable(ctx => ctx.subtleSelection);
6040
const styles = useStyles();
6141

@@ -64,7 +44,6 @@ export const useDataGridRowStyles_unstable = (state: DataGridRowState): DataGrid
6444
dataGridRowClassNames.root,
6545
state.root.className,
6646
isSubtle && styles.subtleSelection,
67-
isHeader && isSingleSelect && styles.singleSelectHeader,
6847
);
6948
if (state.selectionCell) {
7049
state.selectionCell.className = mergeClasses(dataGridRowClassNames.selectionCell, state.selectionCell.className);

packages/react-components/react-table/library/src/components/DataGridSelectionCell/DataGridSelectionCell.test.tsx

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,23 @@ describe('DataGridSelectionCell', () => {
139139
expect((getByRole('checkbox') as HTMLInputElement).checked).toBe(true);
140140
});
141141

142+
it('should not render a radio in the header in single-select mode', () => {
143+
const allRowsSelected = true;
144+
const ctx = mockDataGridContext(
145+
{ selectableRows: true },
146+
{ selection: { allRowsSelected, selectionMode: 'single' } },
147+
);
148+
const { queryByRole } = render(
149+
<DataGridHeader>
150+
<DataGridContextProvider value={ctx}>
151+
<DataGridSelectionCell />
152+
</DataGridContextProvider>
153+
</DataGridHeader>,
154+
);
155+
156+
expect(queryByRole('radio') as HTMLInputElement).toBeFalsy();
157+
});
158+
142159
it('should toggle all rows in multiselect mode', () => {
143160
const toggleAllRows = jest.fn();
144161
const ctx = mockDataGridContext(

packages/react-components/react-table/library/src/components/DataGridSelectionCell/useDataGridSelectionCell.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ export const useDataGridSelectionCell_unstable = (
5252
invisible: isHeader && type === 'radio',
5353
'aria-selected': checked === 'mixed' ? undefined : checked,
5454
subtle,
55+
radioIndicator: isHeader ? null : undefined,
5556
...props,
5657
onClick,
5758
},

0 commit comments

Comments
 (0)