,
+ );
+ });
+
+ // React calls focus on elements in tree order, but only the first
+ // autoFocus element in DOM order should actually be focused in practice.
+ // Both elements will have focus() called, but the second one will
+ // receive focus in the actual DOM.
+ expect(focusedElements).toContain('A');
+ expect(focusedElements).toContain('INPUT');
+ } finally {
+ HTMLElement.prototype.focus = originalFocus;
+ document.body.innerHTML = '';
+ }
+ });
+
+ it('existing form element autoFocus still works alongside anchor autoFocus support', async () => {
+ const originalFocus = HTMLElement.prototype.focus;
+
+ try {
+ const focusedElements = [];
+
+ HTMLElement.prototype.focus = function () {
+ focusedElements.push({tagName: this.tagName, id: this.id});
+ };
+
+ const container = document.createElement('div');
+ document.body.appendChild(container);
+ const root = ReactDOMClient.createRoot(container);
+ await act(() => {
+ root.render(
+
+
+
+
+
+
,
+ );
+ });
+
+ // Verify all form elements still receive focus() calls
+ expect(focusedElements.map(e => e.tagName)).toContain('BUTTON');
+ expect(focusedElements.map(e => e.tagName)).toContain('INPUT');
+ expect(focusedElements.map(e => e.tagName)).toContain('SELECT');
+ expect(focusedElements.map(e => e.tagName)).toContain('TEXTAREA');
+ } finally {
+ HTMLElement.prototype.focus = originalFocus;
+ document.body.innerHTML = '';
+ }
+ });
+
it("shouldn't fire duplicate event handler while handling other nested dispatch", async () => {
const actual = [];