Skip to content

Commit

Permalink
fix: use same style for aria-disabled buttons as disabled
Browse files Browse the repository at this point in the history
  • Loading branch information
MartinWeb committed Dec 27, 2023
1 parent 722cd0c commit 4e68b18
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 1 deletion.
36 changes: 36 additions & 0 deletions packages/button/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
1. [Button circle](#button-circle)
1. [Button with left icon](#button-with-left-icon)
1. [Button with right icon](#button-with-right-icon)
1. [Disabled Button](#disabled-button)

## Installation

Expand Down Expand Up @@ -76,3 +77,38 @@ const RightIconButton = () => (
);
export default RightIconButton;
```

## Disabled Button

For a better accessibility (users to have focus on disabled buttons), you should use the aria-disabled attribute instead of the disabled attribute.

```javascript
const DisabledButton = () => (
<Button classModifier="disabled" aria-disabled>
Lorem Ipsum
<i className="glyphicon glyphicon-arrowthin-right" />
</Button>
);
export default DisabledButton;
```

Be careful that using the aria-disabled attribute will not disable the button, so you have to handle the disabled state inside your onClick or onSubmit function.

```javascript
const disabledButton = true;

<form
onSubmit={event => {
event?.preventDefault();
if (!disabledButton) {
// call function
}
}}>
<Button classModifier="disabled" aria-disabled={disabledButton}>
Lorem Ipsum
<i className="glyphicon glyphicon-arrowthin-right" />
</Button>
</form>
);
export default DisabledButton;
```
2 changes: 1 addition & 1 deletion packages/button/src/Button.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ ButtonSmallStory.args = {
export const ButtonDisabledStory: Story<ButtonProps> = Template.bind({});
ButtonDisabledStory.storyName = 'Button disabled';
ButtonDisabledStory.args = {
disabled: true,
'aria-disabled': true,
classModifier: 'disabled',
children: <span className="af-btn__text">Button disabled</span>,
};
Expand Down
5 changes: 5 additions & 0 deletions packages/button/src/button.scss
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ $active-sort-table-th: $color-table-sorting !default;
}
}

button[aria-disabled='true'] {
/* cursor:pointer set by bootstrap reset needs to be ovveride */
cursor: not-allowed !important;
}

.af-btn {
font-family: $font-family-base;
background-color: $color-azur;
Expand Down

0 comments on commit 4e68b18

Please sign in to comment.