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: added 3 more button attributes #963

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
4 changes: 4 additions & 0 deletions src/components/Button/Button.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,7 @@ Split.args = {
iconProps: {
path: IconName.mdiClockOutline,
},
ariaLabel: 'Dropdown',
},
variant: ButtonVariant.Primary,
};
Expand All @@ -375,6 +376,9 @@ Split_With_Counter.args = {
splitButtonChecked: false,
text: 'Split Button',
variant: ButtonVariant.Primary,
splitButtonProps: {
ariaLabel: 'Dropdown',
},
};

Floating_Button.args = {
Expand Down
6 changes: 6 additions & 0 deletions src/components/Button/Button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ export const Button: FC<ButtonProps> = React.forwardRef(
alignText = ButtonTextAlign.Center,
allowDisabledFocus = false,
ariaLabel,
ariaDescribedby,
ariaHaspopup,
ariaExpanded,
badgeProps,
buttonWidth = ButtonWidth.fitContent,
checked = false,
Expand Down Expand Up @@ -339,6 +342,9 @@ export const Button: FC<ButtonProps> = React.forwardRef(
ref={mergedRef}
aria-disabled={mergedDisabled || loading}
aria-label={ariaLabel}
aria-describedby={ariaDescribedby}
aria-haspopup={ariaHaspopup}
aria-expanded={ariaExpanded}
aria-pressed={toggle ? !!checked : undefined}
defaultChecked={checked}
disabled={(!allowDisabledFocus && mergedDisabled) || loading}
Expand Down
20 changes: 20 additions & 0 deletions src/components/Button/Button.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,14 @@ export enum ButtonVariant {
SystemUI = 'systemui',
}

export enum AriaHaspopupType {
Dialog = 'dialog',
Menu = 'menu',
Listbox = 'listbox',
Tree = 'tree',
Grid = 'grid',
}

export interface FloatingButtonProps {
/**
* Determines if the button is floating.
Expand Down Expand Up @@ -103,6 +111,18 @@ export interface ButtonProps extends NativeButtonProps {
* The button aria-label text.
*/
ariaLabel?: string;
/**
* ID of the element that describes the button.
*/
ariaDescribedby?: string;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why do you need ariaDescribedBy for a button

/**
* Indicates if the button controls a menu or other popover element.
*/
ariaHaspopup?: boolean | AriaHaspopupType;
/**
* Indicates if the popup element controlled by the button is currently expanded or collapsed.
*/
ariaExpanded?: boolean;
/**
* The button counter badge props.
*/
Expand Down
6 changes: 6 additions & 0 deletions src/components/Button/SplitButton/SplitButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ export const SplitButton: FC<SplitButtonProps> = React.forwardRef(
alignText = ButtonTextAlign.Center,
allowDisabledFocus = false,
ariaLabel,
ariaDescribedby,
ariaHaspopup,
ariaExpanded,
classNames,
checked = false,
configContextProps = {
Expand Down Expand Up @@ -169,6 +172,9 @@ export const SplitButton: FC<SplitButtonProps> = React.forwardRef(
ref={mergedRef}
aria-disabled={mergedDisabled}
aria-label={ariaLabel}
aria-describedby={ariaDescribedby}
aria-haspopup={ariaHaspopup}
aria-expanded={ariaExpanded}
aria-pressed={split ? !!checked : undefined}
defaultChecked={checked}
disabled={!allowDisabledFocus && mergedDisabled}
Expand Down
Loading