Skip to content

Commit

Permalink
Add Button support for making the Button description visible.
Browse files Browse the repository at this point in the history
  • Loading branch information
afercia committed Jun 7, 2024
1 parent 8a5c8f1 commit d7315f5
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 5 deletions.
9 changes: 8 additions & 1 deletion packages/components/src/button/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -129,10 +129,17 @@ An optional additional class name to apply to the rendered button.

#### `describedBy`: `string`

An accessible description for the button.
A visually hidden accessible description for the button.

- Required: No

#### `showDescription`: `boolean`

Whether to show the accessible description.

- Required: No
- Default: `false`

#### `disabled`: `boolean`

Whether the button is disabled. If `true`, this will force a `button` element to be rendered, even when an `href` is given.
Expand Down
7 changes: 5 additions & 2 deletions packages/components/src/button/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ export function UnforwardedButton(
variant,
__experimentalIsFocusable: isFocusable,
describedBy,
showDescription,
...buttonOrAnchorProps
} = useDeprecatedProps( props );

Expand Down Expand Up @@ -272,13 +273,15 @@ export function UnforwardedButton(
}
: {};

const DescriptionComponent = showDescription ? 'span' : VisuallyHidden;

return (
<>
<Tooltip { ...tooltipProps }>{ element }</Tooltip>
{ describedBy && (
<VisuallyHidden>
<DescriptionComponent className="components-button__description">
<span id={ descriptionId }>{ describedBy }</span>
</VisuallyHidden>
</DescriptionComponent>
) }
</>
);
Expand Down
11 changes: 10 additions & 1 deletion packages/components/src/button/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,6 @@
/**
* Link buttons.
*/

&.is-link {
margin: 0;
padding: 0;
Expand Down Expand Up @@ -372,6 +371,16 @@
}
}

.components-button__description {
display: block;
margin-top: $grid-unit-10;
margin-bottom: 0;
font-family: inherit;
font-weight: normal;
font-size: $default-font-size;
color: $gray-700;
}

@keyframes components-button__busy-animation {
0% {
background-position: 200px 0;
Expand Down
8 changes: 7 additions & 1 deletion packages/components/src/button/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,15 @@ type BaseButtonProps = {
*/
children?: ReactNode;
/**
* An accessible description for the button.
* A visually hidden accessible description for the button.
*/
describedBy?: string;
/**
* Whether to show the accessible description.
*
* @default false
*/
showDescription?: boolean;
/**
* If provided, renders an Icon component inside the button.
*/
Expand Down

0 comments on commit d7315f5

Please sign in to comment.