Skip to content

Commit 84ff482

Browse files
authored
Revert "fix: Focus behaviour on inputs inside a FocusScope (#8498)" (#8895)
This reverts commit 7df2296.
1 parent 2a75be4 commit 84ff482

File tree

5 files changed

+6
-30
lines changed

5 files changed

+6
-30
lines changed

packages/@react-aria/autocomplete/src/useAutocomplete.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
import {AriaLabelingProps, BaseEvent, DOMProps, FocusableElement, FocusEvents, KeyboardEvents, Node, RefObject, ValueBase} from '@react-types/shared';
1414
import {AriaTextFieldProps} from '@react-aria/textfield';
1515
import {AutocompleteProps, AutocompleteState} from '@react-stately/autocomplete';
16-
import {CLEAR_FOCUS_EVENT, FOCUS_EVENT, getActiveElement, getOwnerDocument, getOwnerWindow, isAndroid, isCtrlKeyPressed, isIOS, mergeProps, mergeRefs, useEffectEvent, useEvent, useLabels, useObjectRef, useSlotId} from '@react-aria/utils';
16+
import {CLEAR_FOCUS_EVENT, FOCUS_EVENT, getActiveElement, getOwnerDocument, isAndroid, isCtrlKeyPressed, isIOS, mergeProps, mergeRefs, useEffectEvent, useEvent, useLabels, useObjectRef, useSlotId} from '@react-aria/utils';
1717
import {dispatchVirtualBlur, dispatchVirtualFocus, getVirtuallyFocusedElement, moveVirtualFocus} from '@react-aria/focus';
1818
import {getInteractionModality} from '@react-aria/interactions';
1919
// @ts-ignore
@@ -106,9 +106,6 @@ export function useAutocomplete<T>(props: AriaAutocompleteOptions<T>, state: Aut
106106
// Ensure input is focused if the user clicks on the collection directly.
107107
if (!e.isTrusted && shouldUseVirtualFocus && inputRef.current && getActiveElement(getOwnerDocument(inputRef.current)) !== inputRef.current) {
108108
inputRef.current.focus();
109-
if (inputRef.current instanceof getOwnerWindow(inputRef.current).HTMLInputElement) {
110-
inputRef.current.select();
111-
}
112109
}
113110

114111
let target = e.target as Element | null;

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

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ import {
1515
getActiveElement,
1616
getEventTarget,
1717
getOwnerDocument,
18-
getOwnerWindow,
1918
isAndroid,
2019
isChrome,
2120
isFocusable,
@@ -372,10 +371,6 @@ function useFocusContainment(scopeRef: RefObject<Element[] | null>, contain?: bo
372371
// restore focus to the previously focused node or the first tabbable element in the active scope.
373372
if (focusedNode.current) {
374373
focusedNode.current.focus();
375-
376-
if (focusedNode.current instanceof getOwnerWindow(focusedNode.current).HTMLInputElement) {
377-
focusedNode.current.select();
378-
}
379374
} else if (activeScope && activeScope.current) {
380375
focusFirstInScope(activeScope.current);
381376
}
@@ -404,9 +399,6 @@ function useFocusContainment(scopeRef: RefObject<Element[] | null>, contain?: bo
404399
if (target && target.isConnected) {
405400
focusedNode.current = target;
406401
focusedNode.current?.focus();
407-
if (focusedNode.current instanceof getOwnerWindow(focusedNode.current).HTMLInputElement) {
408-
focusedNode.current.select();
409-
}
410402
} else if (activeScope.current) {
411403
focusFirstInScope(activeScope.current);
412404
}
@@ -494,9 +486,6 @@ function focusElement(element: FocusableElement | null, scroll = false) {
494486
} else if (element != null) {
495487
try {
496488
element.focus();
497-
if (element instanceof getOwnerWindow(element).HTMLInputElement) {
498-
element.select();
499-
}
500489
} catch {
501490
// ignore
502491
}

packages/@react-aria/interactions/src/focusSafely.ts

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ import {
1515
focusWithoutScrolling,
1616
getActiveElement,
1717
getOwnerDocument,
18-
getOwnerWindow,
1918
runAfterTransition
2019
} from '@react-aria/utils';
2120
import {getInteractionModality} from './useFocusVisible';
@@ -38,15 +37,9 @@ export function focusSafely(element: FocusableElement): void {
3837
// If focus did not move and the element is still in the document, focus it.
3938
if (getActiveElement(ownerDocument) === lastFocusedElement && element.isConnected) {
4039
focusWithoutScrolling(element);
41-
if (element instanceof getOwnerWindow(element).HTMLInputElement) {
42-
element.select();
43-
}
4440
}
4541
});
4642
} else {
4743
focusWithoutScrolling(element);
48-
if (element instanceof getOwnerWindow(element).HTMLInputElement) {
49-
element.select();
50-
}
5144
}
5245
}

packages/@react-spectrum/combobox/test/ComboBox.test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4398,7 +4398,7 @@ describe('ComboBox', function () {
43984398
if (Method === 'escape key') {
43994399
expect(button).toHaveAttribute('aria-labelledby', `${tree.getByText('Test').id} ${tree.getByText('Two').id}`);
44004400
} else {
4401-
expect(button).toHaveAttribute('aria-labelledby', `${tree.getByText('Test').id} ${tree.getByText('r').id}`);
4401+
expect(button).toHaveAttribute('aria-labelledby', `${tree.getByText('Test').id} ${tree.getByText('Twor').id}`);
44024402
}
44034403
tree.unmount();
44044404

@@ -4412,7 +4412,7 @@ describe('ComboBox', function () {
44124412

44134413
await performInteractions(tree);
44144414
expect(() => tree.getByTestId('tray')).toThrow();
4415-
expect(button).toHaveAttribute('aria-labelledby', `${tree.getByText('Test').id} ${tree.getByText('r').id}`);
4415+
expect(button).toHaveAttribute('aria-labelledby', `${tree.getByText('Test').id} ${tree.getByText('Twor').id}`);
44164416
});
44174417

44184418
it('menutrigger=focus doesn\'t reopen the tray on close', async function () {

packages/@react-spectrum/s2/stories/Dialog.stories.tsx

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,12 +48,9 @@ const ExampleRender = (args: ExampleRenderProps): ReactElement => (
4848
<Heading slot="title">Dialog title</Heading>
4949
<Header>Header</Header>
5050
<Content>
51-
<>
52-
{[...Array(args.paragraphs)].map((_, i) =>
53-
<p key={i} style={{marginTop: i === 0 ? 0 : undefined, marginBottom: i === args.paragraphs - 1 ? 0 : undefined}}>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in</p>
54-
)}
55-
<input type="text" defaultValue="Hello" />
56-
</>
51+
{[...Array(args.paragraphs)].map((_, i) =>
52+
<p key={i} style={{marginTop: i === 0 ? 0 : undefined, marginBottom: i === args.paragraphs - 1 ? 0 : undefined}}>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in</p>
53+
)}
5754
</Content>
5855
<Footer><Checkbox>Don't show this again</Checkbox></Footer>
5956
<ButtonGroup>

0 commit comments

Comments
 (0)