Skip to content

Commit 3ab7def

Browse files
committed
fix(Table): use Checkbox isChecked null for indeterminate state
Use the PatternFly Checkbox component's native indeterminate support by setting isChecked to null instead of manually setting the DOM property. This is the correct way to show indeterminate state in PatternFly checkboxes.
1 parent 5024365 commit 3ab7def

1 file changed

Lines changed: 11 additions & 8 deletions

File tree

packages/react-table/src/components/Table/SelectColumn.tsx

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { createRef, Fragment, useEffect } from 'react';
1+
import { createRef, Fragment } from 'react';
22
import { Tooltip, TooltipProps } from '@patternfly/react-core/dist/esm/components/Tooltip';
33
import { Checkbox } from '@patternfly/react-core/dist/esm/components/Checkbox';
44
import { Radio } from '@patternfly/react-core/dist/esm/components/Radio';
@@ -40,16 +40,19 @@ export const SelectColumn: React.FunctionComponent<SelectColumnProps> = ({
4040
}: SelectColumnProps) => {
4141
const inputRef = createRef<any>();
4242

43-
useEffect(() => {
44-
if (inputRef.current && selectVariant === RowSelectVariant.checkbox) {
45-
inputRef.current.indeterminate = !!isIndeterminate;
46-
}
47-
}, [inputRef, isIndeterminate, selectVariant]);
48-
4943
const handleChange = (event: React.FormEvent<HTMLInputElement>, _checked: boolean) => {
5044
onSelect && onSelect(event);
5145
};
5246

47+
// PatternFly Checkbox supports indeterminate via isChecked: null
48+
const checkboxProps = {
49+
...props,
50+
id,
51+
ref: inputRef,
52+
onChange: handleChange,
53+
...(isIndeterminate && { isChecked: null })
54+
};
55+
5356
const commonProps = {
5457
...props,
5558
id,
@@ -60,7 +63,7 @@ export const SelectColumn: React.FunctionComponent<SelectColumnProps> = ({
6063
const content = (
6164
<Fragment>
6265
{selectVariant === RowSelectVariant.checkbox ? (
63-
<Checkbox {...commonProps} />
66+
<Checkbox {...checkboxProps} />
6467
) : (
6568
<Radio {...commonProps} name={name} />
6669
)}

0 commit comments

Comments
 (0)