Skip to content

Commit

Permalink
set tabIndex=-1 on disabled buttons (#2672)
Browse files Browse the repository at this point in the history
  • Loading branch information
giladgray authored Jul 11, 2018
1 parent 3f910a8 commit ccf2cf3
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 3 deletions.
3 changes: 2 additions & 1 deletion packages/core/src/components/button/abstractButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ export abstract class AbstractButton<H extends React.HTMLAttributes<any>> extend
public abstract render(): JSX.Element;

protected getCommonButtonProps() {
const { alignText, fill, large, loading, minimal, small } = this.props;
const { alignText, fill, large, loading, minimal, small, tabIndex } = this.props;
const disabled = this.props.disabled || loading;

const className = classNames(
Expand All @@ -115,6 +115,7 @@ export abstract class AbstractButton<H extends React.HTMLAttributes<any>> extend
onKeyDown: this.handleKeyDown,
onKeyUp: this.handleKeyUp,
ref: this.refHandlers.button,
tabIndex: disabled ? -1 : tabIndex,
};
}

Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/components/button/button.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ Use the `@ns-button` class to access button styles. You should implement buttons
* Add the attribute `tabindex="0"` to make `<a>` tags focusable. `<button>` elements are
focusable by default.
* For buttons implemented with `<a>` tags, add `tabindex="-1"` to disabled buttons to prevent the
user from focusing them by pressing <kbd>tab</kbd> on the keyboard.
user from focusing them by pressing <kbd>tab</kbd> on the keyboard. (This does not happen in the example below.)
* Note that `<a>` tags do not respond to the `:disabled` attribute; use `.@ns-disabled` instead.

@css button
2 changes: 1 addition & 1 deletion packages/core/src/components/button/buttons.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export class AnchorButton extends AbstractButton<React.AnchorHTMLAttributes<HTML
{...removeNonHTMLProps(this.props)}
{...commonProps}
href={commonProps.disabled ? undefined : href}
tabIndex={commonProps.disabled ? undefined : tabIndex}
tabIndex={commonProps.disabled ? -1 : tabIndex}
>
{this.renderChildren()}
</a>
Expand Down

1 comment on commit ccf2cf3

@blueprint-bot
Copy link

Choose a reason for hiding this comment

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

set tabIndex=-1 on disabled buttons (#2672)

Preview: documentation | landing | table

Please sign in to comment.