-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patharia_status.js
51 lines (43 loc) · 1.35 KB
/
aria_status.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
'use strict';
var React = require('react'),
ReactDOM = require('react-dom');
import PropTypes from 'prop-types';
export default class AriaStatus extends React.Component{
static displayName: 'Aria Status'
constructor(props) {
super(props);
this.setTextContent = this.setTextContent.bind(this);
}
componentDidMount() {
var _this = this;
// This is needed as `componentDidUpdate`
// does not fire on the initial render.
_this.setTextContent(_this.props.message);
}
componentDidUpdate() {
var _this = this;
_this.setTextContent(_this.props.message);
}
render() {
return (
React.createElement("span", {
role: "status",
"aria-live": "polite",
style: {
left: '-9999px',
position: 'absolute'
}}
)
);
}
// We cannot set `textContent` directly in `render`,
// because React adds/deletes text nodes when rendering,
// which confuses screen readers and doesn't cause them to read changes.
setTextContent(textContent) {
// We could set `innerHTML`, but it's better to avoid it.
ReactDOM.findDOMNode(this).textContent = textContent || '';
}
}
AriaStatus.propTypes ={
message: PropTypes.string
}