Skip to content

Commit 26e9e42

Browse files
committed
Update for accessability
1 parent f4962e3 commit 26e9e42

4 files changed

Lines changed: 102 additions & 6 deletions

File tree

README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,17 @@ React component for fancy number transitions.
1212
npm i -S che-react-number-easing
1313
```
1414

15+
16+
## Accessibility
17+
18+
`NumberEasing` uses the semantic `<output aria-live="polite">` element to display animated numbers. This ensures that screen readers announce changes to the value automatically.
19+
20+
You can pass custom ARIA attributes (e.g., `aria-label`) to further improve accessibility for your use case:
21+
22+
```jsx
23+
<NumberEasing value={1234} aria-label="Total sales" />
24+
```
25+
1526
## Usage
1627

1728
```jsx

che-react-number-easing-0.2.0.tgz

253 KB
Binary file not shown.

gh-pages/dist/main.css

Lines changed: 85 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,94 @@
11
.demo-card {
2-
max-width: 400px;
2+
max-width: 370px;
33
margin: 3em auto 2em auto;
44
background: #fff;
5-
box-shadow: 0 4px 24px rgba(0, 0, 0, 0.08), 0 1.5px 6px rgba(0, 0, 0, 0.04);
6-
border-radius: 16px;
7-
padding: 2.5em 2em 2em 2em;
5+
box-shadow: 0 2px 12px rgba(0, 0, 0, 0.06);
6+
border-radius: 14px;
7+
padding: 2em 1.5em 1.5em 1.5em;
8+
display: flex;
9+
flex-direction: column;
10+
align-items: center;
11+
font-family: 'Lato', 'Proxima Nova', 'Lato', sans-serif;
12+
}
13+
.demo-title {
14+
font-size: 1.35em;
15+
font-weight: 700;
16+
margin-bottom: 1.2em;
17+
color: #222;
18+
text-align: center;
19+
}
20+
.number-display {
21+
font-size: 2.8em;
22+
font-weight: 700;
23+
color: #8cc34a;
24+
margin-bottom: 1.2em;
25+
text-align: center;
26+
}
27+
.controls {
28+
width: 100%;
829
display: flex;
930
flex-direction: column;
31+
gap: 1em;
32+
margin-bottom: 1.2em;
33+
}
34+
.input-group {
35+
display: flex;
1036
align-items: center;
37+
gap: 0.5em;
38+
justify-content: center;
39+
}
40+
label {
41+
font-size: 1em;
42+
color: #666;
43+
margin-right: 0.2em;
44+
}
45+
.big {
46+
font-size: 1.1em;
47+
padding: 0.4em 0.7em;
48+
border: 1px solid #e0e0e0;
49+
border-radius: 7px;
50+
background: #fafbfc;
51+
width: 7em;
52+
}
53+
.primary-btn {
54+
background: #8cc34a;
55+
color: #fff;
56+
border: none;
57+
border-radius: 7px;
58+
padding: 0.4em 1em;
59+
font-size: 1em;
60+
cursor: pointer;
61+
box-shadow: 0 1px 4px rgba(140, 195, 74, 0.07);
62+
transition: background 0.2s;
63+
}
64+
.primary-btn:hover {
65+
background: #72a436;
66+
}
67+
.secondary-btn {
68+
background: #e0e0e0;
69+
color: #333;
70+
border: none;
71+
border-radius: 7px;
72+
padding: 0.4em 1em;
73+
font-size: 1em;
74+
cursor: pointer;
75+
transition: background 0.2s;
76+
}
77+
.secondary-btn:hover {
78+
background: #d0d0d0;
79+
}
80+
.demo-footer {
81+
width: 100%;
82+
text-align: center;
83+
margin-top: 1.5em;
84+
color: #aaa;
85+
font-size: 0.92em;
86+
line-height: 1.6;
87+
}
88+
.demo-footer a {
89+
color: #aaa;
90+
text-decoration: underline;
91+
font-size: 0.92em;
1192
}
1293
.number-display {
1394
font-size: 3.5em;

src/components/NumberEasing.jsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,13 +80,17 @@ function NumberEasing({
8080

8181
// eslint-disable-next-line react/jsx-props-no-spreading
8282
return (
83-
<span {...other} className={classes}>
83+
<output
84+
{...other}
85+
className={classes}
86+
aria-live="polite"
87+
>
8488
{useLocaleString
8589
? parseFloat(displayValue).toLocaleString(locale, opts)
8690
: trail
8791
? Number(displayValue).toFixed(precision > -1 ? precision : 0)
8892
: Number(displayValue).toString()}
89-
</span>
93+
</output>
9094
);
9195
}
9296

0 commit comments

Comments
 (0)