Skip to content

Commit

Permalink
react-checkbox: update properties to match supported HTML/ARIA attrs (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
smhigley authored Mar 11, 2021
1 parent 376f525 commit a2fea79
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 28 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "prerelease",
"comment": "Update checkbox properties to match allowed HTML/ARIA attributes",
"packageName": "@fluentui/react-checkbox",
"email": "sarah.higley@microsoft.com",
"dependentChangeType": "patch"
}
3 changes: 1 addition & 2 deletions packages/react-checkbox/etc/react-checkbox.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,6 @@ export interface ICheckboxProps extends React.ButtonHTMLAttributes<HTMLElement |
ariaDescribedBy?: string;
ariaLabel?: string;
ariaLabelledBy?: string;
ariaPositionInSet?: number;
ariaSetSize?: number;
as?: React.ElementType;
boxSide?: 'start' | 'end';
checked?: boolean;
Expand All @@ -57,6 +55,7 @@ export interface ICheckboxProps extends React.ButtonHTMLAttributes<HTMLElement |
onChange?: (ev?: React.FormEvent<HTMLElement | HTMLInputElement>, checked?: boolean) => void;
// @deprecated
onRenderLabel?: IRenderFunction<ICheckboxProps>;
required?: boolean;
// @deprecated
styles?: IStyleFunctionOrObject<ICheckboxStyleProps, ICheckboxStyles>;
theme?: ITheme;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,12 @@ export const CheckboxBase: ComponentWithAs<'div', ICheckboxProps> = compose<
'label',
'checkmark',
'disabled',
'required',
'inputProps',
'boxSide',
'ariaLabel',
'ariaLabelledBy',
'ariaDescribedBy',
'ariaPositionInSet',
'ariaSetSize',
'styles',
'onRenderLabel',
'indeterminate',
Expand Down
15 changes: 5 additions & 10 deletions packages/react-checkbox/src/components/Checkbox/Checkbox.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,11 @@ export interface ICheckboxProps
*/
disabled?: boolean;

/**
* Required state of the checkbox.
*/
required?: boolean;

/**
* Callback that is called when the checked value has changed.
*/
Expand Down Expand Up @@ -110,16 +115,6 @@ export interface ICheckboxProps
*/
ariaDescribedBy?: string;

/**
* The position in the parent set (if in a set) for aria-posinset.
*/
ariaPositionInSet?: number;

/**
* The total size of the parent set (if in a set) for aria-setsize.
*/
ariaSetSize?: number;

/**
* Call to provide customized styling that will layer on top of the variant rules.
*
Expand Down
16 changes: 2 additions & 14 deletions packages/react-checkbox/src/components/Checkbox/useCheckbox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,7 @@ import { useFocusRects } from '@fluentui/utilities';
import { ICheckboxProps, ICheckboxState } from './Checkbox.types';

export const useCheckbox = (props: ICheckboxProps, forwardedRef: React.Ref<HTMLElement>): ICheckboxState => {
const {
disabled,
inputProps,
name,
ariaLabel,
ariaLabelledBy,
ariaDescribedBy,
ariaPositionInSet,
ariaSetSize,
title,
label,
} = props;
const { disabled, required, inputProps, name, ariaLabel, ariaLabelledBy, ariaDescribedBy, title, label } = props;

const id = useId('checkbox-', props.id);

Expand Down Expand Up @@ -54,6 +43,7 @@ export const useCheckbox = (props: ICheckboxProps, forwardedRef: React.Ref<HTMLE
ref: inputRef,
checked: !!isChecked,
disabled,
required,
name,
id,
title,
Expand All @@ -63,8 +53,6 @@ export const useCheckbox = (props: ICheckboxProps, forwardedRef: React.Ref<HTMLE
'aria-label': ariaLabel || label,
'aria-labelledby': ariaLabelledBy,
'aria-describedby': ariaDescribedBy,
'aria-posinset': ariaPositionInSet,
'aria-setsize': ariaSetSize,
'aria-checked': isIndeterminate ? 'mixed' : isChecked ? 'true' : 'false',
},
checkbox: {
Expand Down

0 comments on commit a2fea79

Please sign in to comment.