Skip to content

Commit

Permalink
Merge pull request #6679 from LeandroMarcondes/Fix-#6291-Checkbox
Browse files Browse the repository at this point in the history
Fix #6291 Checkbox: Component fail to render when
  • Loading branch information
nitrogenous authored Jul 3, 2024
2 parents 6986b5b + 463ccf4 commit 23c0106
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
6 changes: 6 additions & 0 deletions components/lib/checkbox/Checkbox.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -68,10 +72,12 @@ export const Checkbox = React.memo(
};

const onFocus = () => {
setFocusedState(true);
props?.onFocus?.();
};

const onBlur = () => {
setFocusedState(false);
props?.onBlur?.();
};

Expand Down
12 changes: 12 additions & 0 deletions components/lib/checkbox/checkbox.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export declare type CheckboxPassThroughType<T> = PassThroughType<T, CheckboxPass
export interface CheckboxPassThroughMethodOptions {
props: CheckboxProps;
context: CheckboxContext;
state: CheckboxState;
}

/**
Expand Down Expand Up @@ -74,6 +75,17 @@ export interface CheckboxContext {
disabled: boolean;
}

/**
* Defines current inline state in Checkbox component.
*/
export interface CheckboxState {
/**
* Current focused state as a boolean.
* @defaultValue false
*/
focused: boolean;
}

/**
* Custom change event.
* @see {@link CheckboxProps.onChange}
Expand Down

0 comments on commit 23c0106

Please sign in to comment.