Skip to content

Commit 6d73cd0

Browse files
authored
Fix #7914: TriStateCheckbox 3rd state is NULL not '' (#7916)
1 parent 5f13a57 commit 6d73cd0

3 files changed

Lines changed: 8 additions & 8 deletions

File tree

components/lib/tristatecheckbox/TriStateCheckbox.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import * as React from 'react';
2-
import { useState, useEffect } from 'react';
2+
import { useEffect, useState } from 'react';
33
import { PrimeReactContext, ariaLabel } from '../api/Api';
44
import { useHandleStyle } from '../componentbase/ComponentBase';
55
import { useMergeProps, useMountEffect } from '../hooks/Hooks';
@@ -15,7 +15,7 @@ export const TriStateCheckbox = React.memo(
1515
const context = React.useContext(PrimeReactContext);
1616
const props = TriStateCheckboxBase.getProps(inProps, context);
1717

18-
const [checkBoxValue, setCheckBoxValue] = useState('');
18+
const [checkBoxValue, setCheckBoxValue] = useState(null);
1919
const elementRef = React.useRef(null);
2020

2121
const { ptm, cx, isUnstyled } = TriStateCheckboxBase.setMetaData({
@@ -25,10 +25,10 @@ export const TriStateCheckbox = React.memo(
2525
useHandleStyle(TriStateCheckboxBase.css.styles, isUnstyled, { name: 'tristatecheckbox' });
2626

2727
useEffect(() => {
28-
if ([true, false, ''].includes(props.value)) {
28+
if ([true, false, null].includes(props.value)) {
2929
setCheckBoxValue(props.value);
3030
} else {
31-
setCheckBoxValue('');
31+
setCheckBoxValue(null);
3232
}
3333
}, [props.value]);
3434

@@ -39,12 +39,12 @@ export const TriStateCheckbox = React.memo(
3939

4040
let newValue;
4141

42-
if (checkBoxValue === '') {
42+
if (checkBoxValue === null) {
4343
newValue = true;
4444
} else if (checkBoxValue === true) {
4545
newValue = false;
4646
} else if (checkBoxValue === false) {
47-
newValue = '';
47+
newValue = null;
4848
}
4949

5050
if (props.onChange) {

components/lib/tristatecheckbox/TriStateCheckboxBase.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ export const TriStateCheckboxBase = ComponentBase.extend({
3131
tooltip: null,
3232
tooltipOptions: null,
3333
uncheckIcon: null,
34-
value: '',
34+
value: null,
3535
children: undefined
3636
},
3737
css: {

components/lib/tristatecheckbox/tristatecheckbox.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ export interface TriStateCheckboxProps extends Omit<React.DetailedHTMLProps<Reac
8787
/**
8888
* Value of the TriStateCheckbox.
8989
*/
90-
value?: boolean | string;
90+
value?: boolean | undefined | null;
9191
/**
9292
* When present, it specifies that the component should have invalid state style.
9393
* @defaultValue false

0 commit comments

Comments
 (0)