Skip to content

Commit

Permalink
Merge pull request #2438 from gluestack/feat/radio-forceMount
Browse files Browse the repository at this point in the history
feat: added new prop forceMount
  • Loading branch information
rajat693 authored Sep 3, 2024
2 parents 2f5cdba + 009fdb4 commit 5bd6cc7
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 22 deletions.
20 changes: 10 additions & 10 deletions packages/unstyled/checkbox/src/CheckboxIcon.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,18 @@ import React, { forwardRef } from 'react';
import { useCheckbox } from './CheckboxProvider';

const CheckboxIcon = (StyledCheckboxIcon: any) =>
forwardRef(({ children, ...props }: any, ref?: any) => {
forwardRef(({ children, forceMount = false, ...props }: any, ref?: any) => {
const { isChecked } = useCheckbox('CheckboxContext');

return (
<>
{isChecked && (
<StyledCheckboxIcon {...props} ref={ref}>
{children}
</StyledCheckboxIcon>
)}
</>
);
if (forceMount || isChecked) {
return (
<StyledCheckboxIcon {...props} ref={ref}>
{children}
</StyledCheckboxIcon>
);
}

return null;
});

export default CheckboxIcon;
3 changes: 2 additions & 1 deletion packages/unstyled/checkbox/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ export type ICheckboxComponentType<Root, Indicator, Icon, Label, Group> =
React.RefAttributes<Indicator> & React.PropsWithoutRef<Indicator>
>;
Icon: React.ForwardRefExoticComponent<
React.RefAttributes<Icon> & React.PropsWithoutRef<Icon>
React.RefAttributes<Icon> &
React.PropsWithoutRef<Icon> & { forceMount?: boolean }
>;
Label: React.ForwardRefExoticComponent<
React.RefAttributes<Label> & React.PropsWithoutRef<Label>
Expand Down
20 changes: 10 additions & 10 deletions packages/unstyled/radio/src/RadioIcon.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@ import React, { forwardRef } from 'react';
import { useRadio } from './RadioProvider';

export const RadioIcon = (StyledRadioIcon: any) =>
forwardRef(({ children, ...props }: any, ref?: any) => {
forwardRef(({ children, forceMount = false, ...props }: any, ref?: any) => {
const { isChecked } = useRadio('RadioContext');

return (
<>
{isChecked && (
<StyledRadioIcon {...props} ref={ref}>
{children}
</StyledRadioIcon>
)}
</>
);
if (forceMount || isChecked) {
return (
<StyledRadioIcon {...props} ref={ref}>
{children}
</StyledRadioIcon>
);
}

return null;
});
3 changes: 2 additions & 1 deletion packages/unstyled/radio/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ export type IRadioComponentType<
IRadioGroupProps
>;
Icon: React.ForwardRefExoticComponent<
React.RefAttributes<IconProps> & React.PropsWithoutRef<IconProps>
React.RefAttributes<IconProps> &
React.PropsWithoutRef<IconProps> & { forceMount?: boolean }
>;
Indicator: React.ForwardRefExoticComponent<
React.RefAttributes<IndicatorProps> & React.PropsWithoutRef<IndicatorProps>
Expand Down

0 comments on commit 5bd6cc7

Please sign in to comment.