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

Updated ChoiceGroup to allow callbacks to define one prop type #25475

Merged
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "minor",
"comment": "Make callbacks able to take one param type or the other rather than requiring both.",
"packageName": "@fluentui/react",
"email": "[email protected]",
"dependentChangeType": "patch"
}
10 changes: 5 additions & 5 deletions packages/react/etc/react.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -3348,8 +3348,8 @@ export interface IChoiceGroupOption extends Omit<React_2.InputHTMLAttributes<HTM
imageSrc?: string;
key: string;
labelId?: string;
onRenderField?: IRenderFunction<IChoiceGroupOption | IChoiceGroupOptionProps>;
onRenderLabel?: IRenderFunction<IChoiceGroupOption | IChoiceGroupOptionProps>;
onRenderField?: IRenderFunction<IChoiceGroupOption & IChoiceGroupOptionProps>;
onRenderLabel?: IRenderFunction<IChoiceGroupOption & IChoiceGroupOptionProps>;
selectedImageSrc?: string;
styles?: IStyleFunctionOrObject<IChoiceGroupOptionStyleProps, IChoiceGroupOptionStyles>;
text: string;
Expand All @@ -3364,9 +3364,9 @@ export interface IChoiceGroupOptionProps extends Omit<IChoiceGroupOption, 'key'>
itemKey: string;
key?: string;
name?: string;
onBlur?: (ev?: React_2.FocusEvent<HTMLElement>, props?: IChoiceGroupOption | IChoiceGroupOptionProps) => void;
onChange?: (evt?: React_2.FormEvent<HTMLElement | HTMLInputElement>, props?: IChoiceGroupOption | IChoiceGroupOptionProps) => void;
onFocus?: (ev?: React_2.FocusEvent<HTMLElement | HTMLInputElement>, props?: IChoiceGroupOption | IChoiceGroupOptionProps) => void | undefined;
onBlur?: (ev?: React_2.FocusEvent<HTMLElement>, props?: IChoiceGroupOption & IChoiceGroupOptionProps) => void;
onChange?: (evt?: React_2.FormEvent<HTMLElement | HTMLInputElement>, props?: IChoiceGroupOption & IChoiceGroupOptionProps) => void;
onFocus?: (ev?: React_2.FocusEvent<HTMLElement | HTMLInputElement>, props?: IChoiceGroupOption & IChoiceGroupOptionProps) => void | undefined;
required?: boolean;
theme?: ITheme;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,12 +96,12 @@ export interface IChoiceGroupOption extends Omit<React.InputHTMLAttributes<HTMLE
/**
* Used to customize option rendering.
*/
onRenderField?: IRenderFunction<IChoiceGroupOption | IChoiceGroupOptionProps>;
onRenderField?: IRenderFunction<IChoiceGroupOption & IChoiceGroupOptionProps>;

/**
* Used to customize label rendering.
*/
onRenderLabel?: IRenderFunction<IChoiceGroupOption | IChoiceGroupOptionProps>;
onRenderLabel?: IRenderFunction<IChoiceGroupOption & IChoiceGroupOptionProps>;

/**
* Props for an icon to display with this option.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ export const ChoiceGroupOptionBase: React.FunctionComponent<IChoiceGroupOptionPr
? composeRenderFunction(props.onRenderLabel, defaultOnRenderLabel)
: defaultOnRenderLabel;

const label = onRenderLabel(props);
const label = onRenderLabel({ ...props, key: props.itemKey });

return (
<label htmlFor={id} className={classNames.field}>
Expand Down Expand Up @@ -102,15 +102,15 @@ export const ChoiceGroupOptionBase: React.FunctionComponent<IChoiceGroupOptionPr
const { onRenderField = defaultOnRenderField } = props;

const onChange = (evt: React.FormEvent<HTMLInputElement>): void => {
props.onChange?.(evt, props);
props.onChange?.(evt, { ...props, key: props.itemKey });
};

const onBlur = (evt: React.FocusEvent<HTMLElement>) => {
props.onBlur?.(evt);
};

const onFocus = (evt: React.FocusEvent<HTMLElement>) => {
props.onFocus?.(evt, props);
props.onFocus?.(evt, { ...props, key: props.itemKey });
};

return (
Expand All @@ -130,7 +130,7 @@ export const ChoiceGroupOptionBase: React.FunctionComponent<IChoiceGroupOptionPr
onFocus={onFocus}
onBlur={onBlur}
/>
{onRenderField(props, defaultOnRenderField)}
{onRenderField({ ...props, key: props.itemKey }, defaultOnRenderField)}
</div>
</div>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,21 +34,21 @@ export interface IChoiceGroupOptionProps extends Omit<IChoiceGroupOption, 'key'>
*/
onChange?: (
evt?: React.FormEvent<HTMLElement | HTMLInputElement>,
props?: IChoiceGroupOption | IChoiceGroupOptionProps,
props?: IChoiceGroupOption & IChoiceGroupOptionProps,
) => void;

/**
* Callback for the ChoiceGroup creating the option to be notified when the choice has received focus.
*/
onFocus?: (
ev?: React.FocusEvent<HTMLElement | HTMLInputElement>,
props?: IChoiceGroupOption | IChoiceGroupOptionProps,
props?: IChoiceGroupOption & IChoiceGroupOptionProps,
) => void | undefined;

/**
* Callback for the ChoiceGroup creating the option to be notified when the choice has lost focus.
*/
onBlur?: (ev?: React.FocusEvent<HTMLElement>, props?: IChoiceGroupOption | IChoiceGroupOptionProps) => void;
onBlur?: (ev?: React.FocusEvent<HTMLElement>, props?: IChoiceGroupOption & IChoiceGroupOptionProps) => void;

/**
* Indicates if the ChoiceGroupOption should appear focused, visually
Expand Down