Skip to content

Commit

Permalink
Merge pull request #15 from luukdv/label
Browse files Browse the repository at this point in the history
ARIA label
  • Loading branch information
luukdv authored Apr 4, 2020
2 parents 3d34e63 + 1617e25 commit edfb14d
Show file tree
Hide file tree
Showing 12 changed files with 35 additions and 1 deletion.
1 change: 0 additions & 1 deletion docs/.prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,3 @@
package-lock.json
package.json
public
lib
14 changes: 14 additions & 0 deletions docs/src/components/properties.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,20 @@ export default () => {
</div>
</Example>

<Example>
<Property name="label" initial="undefined" type="string" />
<Hamburger color="white" label="Show menu" size={26} />
An ARIA label to improve accessibility.
<div>
{'<'}
<span className="text-yellow-400">Hamburger</span>
&nbsp;
<span className="text-purple-400">label</span>="
<span className="text-green-400">Show menu</span>
{'" />'}
</div>
</Example>

<Example>
<Property name="rounded" initial="false" type="boolean" />
<Hamburger rounded size={42} />
Expand Down
2 changes: 2 additions & 0 deletions src/Burger.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export const Burger = (({
direction = 'left',
duration = 0.4,
hideOutline = true,
label,
onToggle,
render,
rounded = false,
Expand Down Expand Up @@ -84,6 +85,7 @@ export const Burger = (({
handler,
isLeft: (direction === 'left'),
isToggled,
label,
margin,
move,
time,
Expand Down
1 change: 1 addition & 0 deletions src/Fade.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export const Fade = ((props) => (
<Burger {...props} render={(o) => (
<div
className="hamburger-react"
aria-label={o.label}
data-testid="fade"
onClick={o.handler}
onKeyUp={(e) => (e.key === 'Enter' || e.keyCode === 13) && 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 @@ -6,6 +6,7 @@ export const Sling = ((props) => (
<Burger {...props} render={(o) => (
<div
className="hamburger-react"
aria-label={o.label}
data-testid="sling"
onClick={o.handler}
onKeyUp={(e) => (e.key === 'Enter' || e.keyCode === 13) && 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 @@ -6,6 +6,7 @@ export const Spin = ((props) => (
<Burger {...props} render={(o) => (
<div
className="hamburger-react"
aria-label={o.label}
data-testid="spin"
onClick={o.handler}
onKeyUp={(e) => (e.key === 'Enter' || e.keyCode === 13) && 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 @@ -6,6 +6,7 @@ export const Squash = ((props) => (
<Burger {...props} render={(o) => (
<div
className="hamburger-react"
aria-label={o.label}
data-testid="squash"
onClick={o.handler}
onKeyUp={(e) => (e.key === 'Enter' || e.keyCode === 13) && 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 @@ -6,6 +6,7 @@ export const Tilt = ((props) => (
<Burger {...props} render={(o) => (
<div
className="hamburger-react"
aria-label={o.label}
data-testid="tilt"
onClick={o.handler}
onKeyUp={(e) => (e.key === 'Enter' || e.keyCode === 13) && 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 @@ -6,6 +6,7 @@ export const Turn = ((props) => (
<Burger {...props} render={(o) => (
<div
className="hamburger-react"
aria-label={o.label}
data-testid="turn"
onClick={o.handler}
onKeyUp={(e) => (e.key === 'Enter' || e.keyCode === 13) && 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 @@ -6,6 +6,7 @@ export const Twirl = ((props) => (
<Burger {...props} render={(o) => (
<div
className="hamburger-react"
aria-label={o.label}
data-testid="twirl"
onClick={o.handler}
onKeyUp={(e) => (e.key === 'Enter' || e.keyCode === 13) && o.handler()}
Expand Down
3 changes: 3 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ export interface CommonBurgerProps {
duration?: number;
/** Hides the default browser focus style. */
hideOutline?: boolean;
/** An ARIA label to improve accessibility. */
label?: string;
/** A callback which receives a single boolean argument, indicating if the icon is toggled. */
onToggle?: (toggled: boolean) => any;
/** Specifies if the icon bars should be rounded. */
Expand All @@ -40,6 +42,7 @@ export interface RenderOptions {
handler: () => void;
isLeft: boolean;
isToggled: boolean;
label: string | undefined;
margin: number;
move: number;
/** CSS transition-duration property (in seconds). */
Expand Down
9 changes: 9 additions & 0 deletions tests/label.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import React from 'react'
import Hamburger from '../src'
import { render } from '@testing-library/react'

it(`sets an accessibility label`, () => {
const { getByTestId: get } = render(<Hamburger label="Toggle menu" />)

expect(get('tilt')).toHaveAttribute('aria-label', 'Toggle menu')
})

0 comments on commit edfb14d

Please sign in to comment.