Skip to content

Commit d30c488

Browse files
committed
Dynamically render in content into notification to get screen reader to read alert
1 parent f3c0b34 commit d30c488

File tree

2 files changed

+31
-8
lines changed

2 files changed

+31
-8
lines changed

components/SLDSNotification/index.js

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,17 @@ const propTypes = {
3030

3131
const defaultProps = {
3232
dismissible: true,
33+
isOpen: false
3334
};
3435

3536
class SLDSNotification extends React.Component {
3637
constructor(props){
3738
super(props);
38-
this.state = { isOpen: this.props.isOpen };
39+
this.state = {
40+
isOpen: this.props.isOpen,
41+
interval: null,
42+
addSpace: false,
43+
};
3944
}
4045

4146
componentDidMount() {
@@ -47,9 +52,18 @@ class SLDSNotification extends React.Component {
4752
}
4853
}
4954

55+
componentWillUnmount(){
56+
this.setState({interval: null});
57+
}
58+
5059
componentWillReceiveProps(nextProps){
5160
if(this.props.isOpen !== nextProps.isOpen){
5261
this.setState({ isOpen: nextProps.isOpen });
62+
if(nextProps.isOpen && !this.state.interval){
63+
this.setState({interval: setTimeout(() => {
64+
this.setState({addSpace: !this.state.addSpace});
65+
}, 1000)})
66+
}
5367
}
5468
}
5569

@@ -124,15 +138,24 @@ class SLDSNotification extends React.Component {
124138
});
125139
}
126140

141+
renderContent() {
142+
return (
143+
<div>
144+
{this.state.addSpace ? " x" : ""}
145+
<p ref="test" className="slds-assistive-text">{this.props.theme}</p>
146+
{this.renderClose()}
147+
{this.renderAlertContent()}
148+
{this.renderToastContent()}
149+
</div>
150+
)
151+
}
152+
127153
render(){
128154
if(this.state.isOpen){
129155
return (
130156
<div className="slds-notify-container">
131-
<div className={this.getClassName()} role="alert">
132-
<span className="slds-assistive-text">{this.props.theme}</span>
133-
{this.renderClose()}
134-
{this.renderAlertContent()}
135-
{this.renderToastContent()}
157+
<div ref="alertContent" className={this.getClassName()} role="alert">
158+
{this.renderContent()}
136159
</div>
137160
</div>
138161
);

demo/pages/HomePage/NotificationSection.jsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,8 +116,8 @@ module.exports = React.createClass( {
116116
<h4 className="slds-text-heading--small ">Toasts</h4>
117117
<div className="demo-only" style={toastStyle}>
118118
Base
119-
{this.state.modalIsOpen ? null:
120-
<SLDSNotification variant='toast' theme='success' icon='notification' content={successMsg} onDismiss={this.dismissToast}/>}
119+
{/*this.state.modalIsOpen ? null:
120+
<SLDSNotification variant='toast' theme='success' icon='notification' content={successMsg} onDismiss={this.dismissToast}/>*/}
121121
</div>
122122

123123
<p>Modal Toasts</p>

0 commit comments

Comments
 (0)