Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #6291 Checkbox: Component fail to render when #6679

Merged
merged 1 commit into from
Jul 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading