Skip to content

Commit bf28389

Browse files
refactor(a11y): move sr-only styles from CSS to inline JavaScript
1 parent a61fea7 commit bf28389

File tree

2 files changed

+9
-12
lines changed

2 files changed

+9
-12
lines changed

demo/styles.css

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -112,15 +112,3 @@ button:hover {
112112
position: relative;
113113
display: inline-block;
114114
}
115-
116-
.sr-only {
117-
position: absolute;
118-
width: 1px;
119-
height: 1px;
120-
padding: 0;
121-
margin: -1px;
122-
overflow: hidden;
123-
clip: rect(0, 0, 0, 0);
124-
white-space: nowrap;
125-
border: 0;
126-
}

src/index.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,15 @@ export default class SplitText {
101101
if (!this.options.noAriaLabel) {
102102
const span = document.createElement('span');
103103
span.classList.add('sr-only');
104+
span.style.setProperty('position', 'absolute');
105+
span.style.setProperty('width', '1px');
106+
span.style.setProperty('height', '1px');
107+
span.style.setProperty('padding', '0');
108+
span.style.setProperty('margin', '-1px');
109+
span.style.setProperty('overflow', 'hidden');
110+
span.style.setProperty('clip', 'rect(0, 0, 0, 0)');
111+
span.style.setProperty('white-space', 'nowrap');
112+
span.style.setProperty('border', '0');
104113
span.textContent = this.ariaLabel.join(' ');
105114
element.appendChild(span);
106115
}

0 commit comments

Comments
 (0)