Skip to content

Commit 51d58eb

Browse files
felixzapatajavivelasco
authored andcommitted
Alternative text for the FontIcon
* refactor(FontIcon): remove unused attribute * feat(a11y): set aria-label attribute to the icon
1 parent 78895c0 commit 51d58eb

File tree

3 files changed

+11
-9
lines changed

3 files changed

+11
-9
lines changed

components/font_icon/FontIcon.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,19 @@
11
import React, { PropTypes } from 'react';
22
import classnames from 'classnames';
33

4-
const FontIcon = ({ children, className, value, ...other}) => (
4+
const FontIcon = ({ alt, children, className, value, ...other}) => (
55
<span
66
data-react-toolbox='font-icon'
7+
aria-label={alt}
78
className={classnames({'material-icons': typeof value === 'string' || typeof children === 'string'}, className)}
89
{...other}
910
>
10-
{value}
11-
{children}
11+
<span aria-hidden="true">{value}</span>
1212
</span>
1313
);
1414

1515
FontIcon.propTypes = {
16+
alt: PropTypes.string,
1617
children: PropTypes.any,
1718
className: PropTypes.string,
1819
value: PropTypes.oneOfType([
@@ -22,6 +23,7 @@ FontIcon.propTypes = {
2223
};
2324

2425
FontIcon.defaultProps = {
26+
alt: '',
2527
className: ''
2628
};
2729

components/font_icon/readme.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,6 @@ const FontIcons = () => (
2020

2121
| Name | Type | Default | Description|
2222
|:-----|:-----|:-----|:-----|
23-
| `children` | `String` | | The key string for the icon you want to be displayed.|
23+
| `alt` | `String` | `''` | The text used to set the `aria-label` attribute.
2424
| `className` | `String` | `''` | The class name to give custom styles such as sizing.|
2525
| `value` | `String` or `Element` | | The key string for the icon you want be displayed.|

spec/components/font_icon.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@ const FontIconTest = () => (
66
<h5>Font Icons</h5>
77
<p>lorem ipsum...</p>
88

9-
<FontIcon value="add"/>
10-
<FontIcon value="access_alarm"/>
11-
<FontIcon value="explore"/>
12-
<FontIcon value="zoom_in"/>
13-
<FontIcon>input</FontIcon>
9+
<FontIcon value="add" alt="add icon" />
10+
<FontIcon value="access_alarm" />
11+
<FontIcon value="explore" alt="explore icon" />
12+
<FontIcon value="zoom_in" alt="zoom icon" />
13+
<FontIcon alt="input icon">input</FontIcon>
1414
</section>
1515
);
1616

0 commit comments

Comments
 (0)