Skip to content

Commit 54bcbfa

Browse files
authored
fix(ToggleButton): remove role="button" from label (react-bootstrap#6204)
1 parent 43edf44 commit 54bcbfa

File tree

4 files changed

+41
-28
lines changed

4 files changed

+41
-28
lines changed

src/Button.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,8 @@ const Button: BsPrefixRefForwardingComponent<'button', ButtonProps> =
8686

8787
return (
8888
<Component
89-
{...props}
9089
{...buttonProps}
90+
{...props}
9191
ref={ref}
9292
className={classNames(
9393
className,

src/ToggleButton.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ const ToggleButton = React.forwardRef<HTMLLabelElement, ToggleButtonProps>(
112112
ref={ref}
113113
className={classNames(className, disabled && 'disabled')}
114114
type={undefined}
115+
role={undefined}
115116
as="label"
116117
htmlFor={id}
117118
/>

test/ToggleButtonGroupSpec.tsx

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,8 @@
1-
import * as React from 'react';
21
import { render, fireEvent } from '@testing-library/react';
32
import sinon from 'sinon';
43

54
import ToggleButtonGroup from '../src/ToggleButtonGroup';
65

7-
describe('ToggleButton', () => {
8-
it('should forward refs to the label', () => {
9-
const ref = React.createRef<HTMLLabelElement>();
10-
render(
11-
<div>
12-
<ToggleButtonGroup.Button id="id" ref={ref} value={3}>
13-
Option 3
14-
</ToggleButtonGroup.Button>
15-
</div>,
16-
);
17-
18-
ref.current!.tagName.should.equal('LABEL');
19-
});
20-
21-
it('should add an inputRef', () => {
22-
const ref = React.createRef<HTMLInputElement>();
23-
render(
24-
<ToggleButtonGroup.Button id="id" inputRef={ref} value={3}>
25-
Option 3
26-
</ToggleButtonGroup.Button>,
27-
);
28-
29-
ref.current!.tagName.should.equal('INPUT');
30-
});
31-
});
32-
336
describe('ToggleButtonGroup', () => {
347
it('should render checkboxes', () => {
358
const { container, getByLabelText } = render(

test/ToggleButtonSpec.tsx

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import * as React from 'react';
2+
import { render } from '@testing-library/react';
3+
import { expect } from 'chai';
4+
5+
import ToggleButton from '../src/ToggleButton';
6+
7+
describe('ToggleButton', () => {
8+
it('should forward refs to the label', () => {
9+
const ref = React.createRef<HTMLLabelElement>();
10+
render(
11+
<ToggleButton id="id" ref={ref} value={1}>
12+
Option
13+
</ToggleButton>,
14+
);
15+
16+
ref.current!.tagName.should.equal('LABEL');
17+
});
18+
19+
it('should add an inputRef', () => {
20+
const ref = React.createRef<HTMLInputElement>();
21+
render(
22+
<ToggleButton id="id" inputRef={ref} value={1}>
23+
Option
24+
</ToggleButton>,
25+
);
26+
27+
ref.current!.tagName.should.equal('INPUT');
28+
});
29+
30+
it('should not have a role on the label button', () => {
31+
const { getByText } = render(
32+
<ToggleButton id="id" value={1}>
33+
Option
34+
</ToggleButton>,
35+
);
36+
37+
expect(getByText('Option').getAttribute('role')).to.not.exist;
38+
});
39+
});

0 commit comments

Comments
 (0)