From 463ccf4eed7a629203b6be02d86e3872fc85c7d4 Mon Sep 17 00:00:00 2001 From: Leandro Abreu Date: Mon, 27 May 2024 11:23:08 +1000 Subject: [PATCH] Fix #6291 Checkbox: Component fail to render when using the state on pt property --- components/lib/checkbox/Checkbox.js | 6 ++++++ components/lib/checkbox/checkbox.d.ts | 12 ++++++++++++ 2 files changed, 18 insertions(+) diff --git a/components/lib/checkbox/Checkbox.js b/components/lib/checkbox/Checkbox.js index be08e01422..6889e80dc0 100644 --- a/components/lib/checkbox/Checkbox.js +++ b/components/lib/checkbox/Checkbox.js @@ -12,8 +12,12 @@ export const Checkbox = React.memo( const mergeProps = useMergeProps(); const context = React.useContext(PrimeReactContext); const props = CheckboxBase.getProps(inProps, context); + const [focusedState, setFocusedState] = React.useState(false); const { ptm, cx, isUnstyled } = CheckboxBase.setMetaData({ props, + state: { + focused: focusedState + }, context: { checked: props.checked === props.trueValue, disabled: props.disabled @@ -68,10 +72,12 @@ export const Checkbox = React.memo( }; const onFocus = () => { + setFocusedState(true); props?.onFocus?.(); }; const onBlur = () => { + setFocusedState(false); props?.onBlur?.(); }; diff --git a/components/lib/checkbox/checkbox.d.ts b/components/lib/checkbox/checkbox.d.ts index 19706c887a..fab8626738 100644 --- a/components/lib/checkbox/checkbox.d.ts +++ b/components/lib/checkbox/checkbox.d.ts @@ -23,6 +23,7 @@ export declare type CheckboxPassThroughType = PassThroughType