Skip to content

Commit 907c0b1

Browse files
authored
feat(v5): rename screen reader classes (react-bootstrap#5665)
1 parent db8d137 commit 907c0b1

25 files changed

+75
-49
lines changed

src/Carousel.tsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -608,13 +608,17 @@ function CarouselFunc(uncontrolledProps: CarouselProps, ref) {
608608
{(wrap || activeIndex !== 0) && (
609609
<SafeAnchor className={`${prefix}-control-prev`} onClick={prev}>
610610
{prevIcon}
611-
{prevLabel && <span className="sr-only">{prevLabel}</span>}
611+
{prevLabel && (
612+
<span className="visually-hidden">{prevLabel}</span>
613+
)}
612614
</SafeAnchor>
613615
)}
614616
{(wrap || activeIndex !== numChildren - 1) && (
615617
<SafeAnchor className={`${prefix}-control-next`} onClick={next}>
616618
{nextIcon}
617-
{nextLabel && <span className="sr-only">{nextLabel}</span>}
619+
{nextLabel && (
620+
<span className="visually-hidden">{nextLabel}</span>
621+
)}
618622
</SafeAnchor>
619623
)}
620624
</>

src/FormLabel.tsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import {
1313

1414
interface FormLabelBaseProps extends BsPrefixPropsWithChildren {
1515
htmlFor?: string;
16-
srOnly?: boolean;
16+
visuallyHidden?: boolean;
1717
}
1818

1919
export interface FormLabelOwnProps extends FormLabelBaseProps {
@@ -59,15 +59,15 @@ const propTypes = {
5959
* Hides the label visually while still allowing it to be
6060
* read by assistive technologies.
6161
*/
62-
srOnly: PropTypes.bool,
62+
visuallyHidden: PropTypes.bool,
6363

6464
/** Set a custom element for this component */
6565
as: PropTypes.elementType,
6666
};
6767

6868
const defaultProps = {
6969
column: false,
70-
srOnly: false,
70+
visuallyHidden: false,
7171
};
7272

7373
const FormLabel: FormLabel = React.forwardRef(
@@ -77,7 +77,7 @@ const FormLabel: FormLabel = React.forwardRef(
7777
as: Component = 'label',
7878
bsPrefix,
7979
column,
80-
srOnly,
80+
visuallyHidden,
8181
className,
8282
htmlFor,
8383
...props
@@ -95,7 +95,7 @@ const FormLabel: FormLabel = React.forwardRef(
9595
const classes = classNames(
9696
className,
9797
bsPrefix,
98-
srOnly && 'sr-only',
98+
visuallyHidden && 'visually-hidden',
9999
column && columnClass,
100100
);
101101

src/PageItem.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ const PageItem: PageItem = React.forwardRef<HTMLLIElement, PageItemProps>(
6363
<Component className="page-link" disabled={disabled} {...props}>
6464
{children}
6565
{active && activeLabel && (
66-
<span className="sr-only">{activeLabel}</span>
66+
<span className="visually-hidden">{activeLabel}</span>
6767
)}
6868
</Component>
6969
</li>
@@ -82,7 +82,7 @@ function createButton(name: string, defaultValue: ReactNode, label = name) {
8282
return (
8383
<PageItem {...props}>
8484
<span aria-hidden="true">{children || defaultValue}</span>
85-
<span className="sr-only">{label}</span>
85+
<span className="visually-hidden">{label}</span>
8686
</PageItem>
8787
);
8888
}

src/ProgressBar.tsx

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ export interface ProgressBarProps
1414
now?: number;
1515
max?: number;
1616
label?: React.ReactNode;
17-
srOnly?: boolean;
17+
visuallyHidden?: boolean;
1818
striped?: boolean;
1919
animated?: boolean;
2020
variant?: 'success' | 'danger' | 'warning' | 'info' | string;
@@ -86,7 +86,7 @@ const propTypes = {
8686
/**
8787
* Hide's the label visually.
8888
*/
89-
srOnly: PropTypes.bool,
89+
visuallyHidden: PropTypes.bool,
9090

9191
/**
9292
* Uses a gradient to create a striped effect.
@@ -127,7 +127,7 @@ const defaultProps = {
127127
max: 100,
128128
animated: false,
129129
isChild: false,
130-
srOnly: false,
130+
visuallyHidden: false,
131131
striped: false,
132132
};
133133

@@ -142,7 +142,7 @@ function renderProgressBar(
142142
now,
143143
max,
144144
label,
145-
srOnly,
145+
visuallyHidden,
146146
striped,
147147
animated,
148148
className,
@@ -168,7 +168,11 @@ function renderProgressBar(
168168
aria-valuemin={min}
169169
aria-valuemax={max}
170170
>
171-
{srOnly ? <span className="sr-only">{label}</span> : label}
171+
{visuallyHidden ? (
172+
<span className="visually-hidden">{label}</span>
173+
) : (
174+
label
175+
)}
172176
</div>
173177
);
174178
}
@@ -188,7 +192,7 @@ const ProgressBar = React.forwardRef<HTMLDivElement, ProgressBarProps>(
188192
now,
189193
max,
190194
label,
191-
srOnly,
195+
visuallyHidden,
192196
striped,
193197
animated,
194198
bsPrefix,
@@ -212,7 +216,7 @@ const ProgressBar = React.forwardRef<HTMLDivElement, ProgressBarProps>(
212216
now,
213217
max,
214218
label,
215-
srOnly,
219+
visuallyHidden,
216220
striped,
217221
animated,
218222
bsPrefix,

src/SplitButton.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ const SplitButton = React.forwardRef<HTMLElement, SplitButtonProps>(
143143
disabled={props.disabled}
144144
childBsPrefix={bsPrefix}
145145
>
146-
<span className="sr-only">{toggleLabel}</span>
146+
<span className="visually-hidden">{toggleLabel}</span>
147147
</Dropdown.Toggle>
148148

149149
<Dropdown.Menu

test/CarouselSpec.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ describe('<Carousel>', () => {
219219
</Carousel>,
220220
);
221221

222-
const labels = wrapper.find('.sr-only');
222+
const labels = wrapper.find('.visually-hidden');
223223

224224
expect(labels).to.have.lengthOf(2);
225225
expect(labels.at(0).text()).to.equal('Previous awesomeness');
@@ -240,7 +240,7 @@ describe('<Carousel>', () => {
240240
</Carousel>,
241241
);
242242

243-
expect(wrapper.find('.sr-only')).to.have.lengthOf(
243+
expect(wrapper.find('.visually-hidden')).to.have.lengthOf(
244244
0,
245245
`should not render labels for value ${falsyValue}`,
246246
);

test/FormLabelSpec.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,9 @@ describe('<FormLabel>', () => {
3535
).assertSingle('label[htmlFor="foo"].col-sm-4.col-form-label');
3636
});
3737

38-
it('should respect srOnly', () => {
39-
mount(<FormLabel srOnly>Label</FormLabel>).assertSingle(
40-
'label.form-label.sr-only',
38+
it('should respect visuallyHidden', () => {
39+
mount(<FormLabel visuallyHidden>Label</FormLabel>).assertSingle(
40+
'label.form-label.visually-hidden',
4141
);
4242
});
4343

test/ProgressBarSpec.js

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,12 +83,12 @@ describe('<ProgressBar>', () => {
8383
min={0}
8484
max={10}
8585
now={5}
86-
srOnly
86+
visuallyHidden
8787
variant="success"
8888
label="progress bar label"
8989
/>,
9090
)
91-
.find('.sr-only')
91+
.find('.visually-hidden')
9292
.getDOMNode();
9393

9494
assert.equal(node.textContent, 'progress bar label');
@@ -106,8 +106,14 @@ describe('<ProgressBar>', () => {
106106
const customLabel = <strong className="special-label">My label</strong>;
107107

108108
mount(
109-
<ProgressBar min={0} max={10} now={5} label={customLabel} srOnly />,
110-
).find('.sr-only .special-label');
109+
<ProgressBar
110+
min={0}
111+
max={10}
112+
now={5}
113+
label={customLabel}
114+
visuallyHidden
115+
/>,
116+
).find('.visually-hidden .special-label');
111117
});
112118

113119
it('Should show striped bar', () => {

test/SplitButtonSpec.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ describe('<SplitButton>', () => {
8383

8484
it('should set accessible label on toggle', () => {
8585
mount(simple)
86-
.assertSingle('.sr-only')
86+
.assertSingle('.visually-hidden')
8787
.text()
8888
.should.equal('Toggle dropdown');
8989
});
@@ -94,7 +94,7 @@ describe('<SplitButton>', () => {
9494
<DropdownItem>Item 1</DropdownItem>
9595
</SplitButton>,
9696
)
97-
.assertSingle('.sr-only')
97+
.assertSingle('.visually-hidden')
9898
.text()
9999
.should.equal('Label');
100100
});

tests/simple-types-test.tsx

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -417,7 +417,7 @@ const MegaComponent = () => (
417417
as="div"
418418
column="sm"
419419
htmlFor="id"
420-
srOnly
420+
visuallyHidden
421421
bsPrefix="formlabel"
422422
style={style}
423423
>
@@ -895,7 +895,13 @@ const MegaComponent = () => (
895895
<ProgressBar striped animated variant="info" now={20} />
896896
<ProgressBar striped variant="warning" now={60} />
897897
<ProgressBar striped variant="danger" now={80} />
898-
<ProgressBar id="id" label="label" srOnly bsPrefix="prefix" style={style}>
898+
<ProgressBar
899+
id="id"
900+
label="label"
901+
visuallyHidden
902+
bsPrefix="prefix"
903+
style={style}
904+
>
899905
<ProgressBar isChild />
900906
</ProgressBar>
901907
</div>

0 commit comments

Comments
 (0)