Skip to content

Commit

Permalink
Merge pull request #47 from jgrenat/add-aria-expanded
Browse files Browse the repository at this point in the history
Add aria-expanded attribute for accessibility
  • Loading branch information
Luuk de Vlieger authored Oct 9, 2021
2 parents c609183 + e6c62a5 commit 059699c
Show file tree
Hide file tree
Showing 15 changed files with 29 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/Cross.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export const Cross = ((props) => (
<div
className="hamburger-react"
aria-label={o.label}
aria-expanded={o.isToggled}
data-testid="cross"
onClick={o.handler}
onKeyUp={(e) => e.key === 'Enter' && o.handler()}
Expand Down
1 change: 1 addition & 0 deletions src/Divide.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export const Divide = ((props) => (
<div
className="hamburger-react"
aria-label={o.label}
aria-expanded={o.isToggled}
data-testid="divide"
onClick={o.handler}
onKeyUp={(e) => e.key === 'Enter' && o.handler()}
Expand Down
1 change: 1 addition & 0 deletions src/Fade.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export const Fade = ((props) => (
<div
className="hamburger-react"
aria-label={o.label}
aria-expanded={o.isToggled}
data-testid="fade"
onClick={o.handler}
onKeyUp={(e) => e.key === 'Enter' && o.handler()}
Expand Down
1 change: 1 addition & 0 deletions src/Pivot.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export const Pivot = ((props) => (
<div
className="hamburger-react"
aria-label={o.label}
aria-expanded={o.isToggled}
data-testid="pivot"
onClick={o.handler}
onKeyUp={(e) => e.key === 'Enter' && o.handler()}
Expand Down
1 change: 1 addition & 0 deletions src/Rotate.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export const Rotate = ((props) => (
<div
className="hamburger-react"
aria-label={o.label}
aria-expanded={o.isToggled}
data-testid="rotate"
onClick={o.handler}
onKeyUp={(e) => e.key === 'Enter' && o.handler()}
Expand Down
1 change: 1 addition & 0 deletions src/Slant.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export const Slant = ((props) => (
<div
className="hamburger-react"
aria-label={o.label}
aria-expanded={o.isToggled}
data-testid="slant"
onClick={o.handler}
onKeyUp={(e) => e.key === 'Enter' && o.handler()}
Expand Down
1 change: 1 addition & 0 deletions src/Sling.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export const Sling = ((props) => (
<div
className="hamburger-react"
aria-label={o.label}
aria-expanded={o.isToggled}
data-testid="sling"
onClick={o.handler}
onKeyUp={(e) => e.key === 'Enter' && o.handler()}
Expand Down
1 change: 1 addition & 0 deletions src/Spin.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export const Spin = ((props) => (
<div
className="hamburger-react"
aria-label={o.label}
aria-expanded={o.isToggled}
data-testid="spin"
onClick={o.handler}
onKeyUp={(e) => e.key === 'Enter' && o.handler()}
Expand Down
1 change: 1 addition & 0 deletions src/Spiral.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export const Spiral = ((props) => (
<div
className="hamburger-react"
aria-label={o.label}
aria-expanded={o.isToggled}
data-testid="spiral"
onClick={o.handler}
onKeyUp={(e) => e.key === 'Enter' && o.handler()}
Expand Down
1 change: 1 addition & 0 deletions src/Squash.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export const Squash = ((props) => (
<div
className="hamburger-react"
aria-label={o.label}
aria-expanded={o.isToggled}
data-testid="squash"
onClick={o.handler}
onKeyUp={(e) => e.key === 'Enter' && o.handler()}
Expand Down
1 change: 1 addition & 0 deletions src/Squeeze.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export const Squeeze = ((props) => (
<div
className="hamburger-react"
aria-label={o.label}
aria-expanded={o.isToggled}
data-testid="squeeze"
onClick={o.handler}
onKeyUp={(e) => e.key === 'Enter' && o.handler()}
Expand Down
1 change: 1 addition & 0 deletions src/Tilt.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export const Tilt = ((props) => (
<div
className="hamburger-react"
aria-label={o.label}
aria-expanded={o.isToggled}
data-testid="tilt"
onClick={o.handler}
onKeyUp={(e) => e.key === 'Enter' && o.handler()}
Expand Down
1 change: 1 addition & 0 deletions src/Turn.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export const Turn = ((props) => (
<div
className="hamburger-react"
aria-label={o.label}
aria-expanded={o.isToggled}
data-testid="turn"
onClick={o.handler}
onKeyUp={(e) => e.key === 'Enter' && o.handler()}
Expand Down
1 change: 1 addition & 0 deletions src/Twirl.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export const Twirl = ((props) => (
<div
className="hamburger-react"
aria-label={o.label}
aria-expanded={o.isToggled}
data-testid="twirl"
onClick={o.handler}
onKeyUp={(e) => e.key === 'Enter' && o.handler()}
Expand Down
15 changes: 15 additions & 0 deletions tests/ariaExpanded.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import React from 'react'
import Hamburger from '../src'
import {render, screen} from '@testing-library/react'

it(`has an expansion indicator (for accessibility) when toggled`, () => {
render(<Hamburger toggled />)

expect(screen.getByTestId('tilt')).toHaveAttribute('aria-expanded', 'true')
})

it(`doesn't have an expansion indicator (for accessibility) when closed`, () => {
render(<Hamburger />)

expect(screen.getByTestId('tilt')).toHaveAttribute('aria-expanded', 'false')
})

0 comments on commit 059699c

Please sign in to comment.