Skip to content

Commit

Permalink
feat(Button) : Add aria-pressed attribute for toggle button (#3330)
Browse files Browse the repository at this point in the history
  • Loading branch information
shufflerAbhi authored and levithomason committed Dec 9, 2018
1 parent 93c918b commit 132e73f
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/elements/Button/Button.js
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,7 @@ class Button extends Component {
{labelPosition === 'left' && labelElement}
<button
className={buttonClasses}
aria-pressed={toggle ? (!!active) : undefined}
disabled={disabled}
ref={this.handleRef}
tabIndex={tabIndex}
Expand All @@ -287,6 +288,7 @@ class Button extends Component {
<ElementType
{...rest}
className={classes}
aria-pressed={toggle ? (!!active) : undefined}
disabled={(disabled && ElementType === 'button') || undefined}
onClick={this.handleClick}
ref={this.handleRef}
Expand Down
18 changes: 18 additions & 0 deletions test/specs/elements/Button/Button-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,24 @@ describe('Button', () => {
})
})

describe('toggle', () => {
it('is not set by default', () => {
shallow(<Button />).should.not.have.prop('toggle')
})

it('should have aria-pressed', () => {
shallow(<Button toggle />).should.have.prop('aria-pressed')
})

it('aria-pressed should be true when active', () => {
shallow(<Button toggle active />).should.have.prop('aria-pressed', true)
})

it('aria-pressed should be false when inactive', () => {
shallow(<Button toggle />).should.have.prop('aria-pressed', false)
})
})

describe('icon', () => {
it('adds className icon', () => {
shallow(<Button icon='user' />).should.have.className('icon')
Expand Down

0 comments on commit 132e73f

Please sign in to comment.