Skip to content

Commit 99d073a

Browse files
fix: tabbing past contenteditable=false in containing focusscope (#7340)
* fix: spinbutton tabindex when disabled * fix: spectrum test suite * fix: review comments * chore: remove package.json changes * Add test --------- Co-authored-by: Robert Snow <[email protected]> Co-authored-by: GitHub <[email protected]>
1 parent b0f1569 commit 99d073a

File tree

2 files changed

+40
-1
lines changed

2 files changed

+40
-1
lines changed

packages/@react-aria/focus/src/FocusScope.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ const focusableElements = [
280280
'embed',
281281
'audio[controls]',
282282
'video[controls]',
283-
'[contenteditable]'
283+
'[contenteditable]:not([contenteditable^="false"])'
284284
];
285285

286286
const FOCUSABLE_ELEMENT_SELECTOR = focusableElements.join(':not([hidden]),') + ',[tabindex]:not([disabled]):not([hidden])';

packages/@react-aria/focus/test/FocusScope.test.js

+39
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,45 @@ describe('FocusScope', function () {
155155
expect(document.activeElement).toBe(input1);
156156
});
157157

158+
it('should only skip content editable which are false', async function () {
159+
let {getByTestId} = render(
160+
<FocusScope contain>
161+
<input data-testid="input1" />
162+
<span contentEditable data-testid="input2" />
163+
<span contentEditable="false" />
164+
<span contentEditable={false} />
165+
<span contentEditable="plaintext-only" data-testid="input3" />
166+
<input data-testid="input4" />
167+
</FocusScope>
168+
);
169+
170+
let input1 = getByTestId('input1');
171+
let input2 = getByTestId('input2');
172+
let input3 = getByTestId('input3');
173+
let input4 = getByTestId('input4');
174+
175+
act(() => {input1.focus();});
176+
expect(document.activeElement).toBe(input1);
177+
178+
await user.tab();
179+
expect(document.activeElement).toBe(input2);
180+
181+
await user.tab();
182+
expect(document.activeElement).toBe(input3);
183+
184+
await user.tab();
185+
expect(document.activeElement).toBe(input4);
186+
187+
await user.tab({shift: true});
188+
expect(document.activeElement).toBe(input3);
189+
190+
await user.tab({shift: true});
191+
expect(document.activeElement).toBe(input2);
192+
193+
await user.tab({shift: true});
194+
expect(document.activeElement).toBe(input1);
195+
});
196+
158197
it('should do nothing if a modifier key is pressed', function () {
159198
let {getByTestId} = render(
160199
<FocusScope contain>

0 commit comments

Comments
 (0)