From 2b2bc35d3da32c662050645838a903bf479d58fc Mon Sep 17 00:00:00 2001 From: Eric Olkowski <70952936+thatblindgeye@users.noreply.github.com> Date: Wed, 23 Oct 2024 11:24:58 -0400 Subject: [PATCH] fix(Select/Dropdown): updated autofocus to false by default in v6 (#11115) * fix(Select/Dropdown): updated autofocus to false by default in v6 * Updated expectation in cypress test --- .../react-core/src/components/Dropdown/Dropdown.tsx | 2 +- packages/react-core/src/components/Select/Select.tsx | 2 +- .../cypress/integration/dropdown.spec.ts | 10 +++++----- .../src/components/demos/DropdownDemo/DropdownDemo.tsx | 4 ++-- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/packages/react-core/src/components/Dropdown/Dropdown.tsx b/packages/react-core/src/components/Dropdown/Dropdown.tsx index 84835a0f0ea..0fd713e66cc 100644 --- a/packages/react-core/src/components/Dropdown/Dropdown.tsx +++ b/packages/react-core/src/components/Dropdown/Dropdown.tsx @@ -91,7 +91,7 @@ const DropdownBase: React.FunctionComponent = ({ onOpenChangeKeys = ['Escape', 'Tab'], menuHeight, maxMenuHeight, - shouldFocusFirstItemOnOpen = true, + shouldFocusFirstItemOnOpen = false, ...props }: DropdownProps) => { const localMenuRef = React.useRef(); diff --git a/packages/react-core/src/components/Select/Select.tsx b/packages/react-core/src/components/Select/Select.tsx index 50e022cd858..2edf7638af7 100644 --- a/packages/react-core/src/components/Select/Select.tsx +++ b/packages/react-core/src/components/Select/Select.tsx @@ -88,7 +88,7 @@ const SelectBase: React.FunctionComponent = ({ selected, toggle, shouldFocusToggleOnSelect = false, - shouldFocusFirstItemOnOpen = true, + shouldFocusFirstItemOnOpen = false, onOpenChange, onOpenChangeKeys = ['Escape', 'Tab'], isPlain, diff --git a/packages/react-integration/cypress/integration/dropdown.spec.ts b/packages/react-integration/cypress/integration/dropdown.spec.ts index 63cc940b955..b445d253269 100644 --- a/packages/react-integration/cypress/integration/dropdown.spec.ts +++ b/packages/react-integration/cypress/integration/dropdown.spec.ts @@ -43,14 +43,14 @@ describe('Dropdown demo test', () => { so testing for a button click should be sufficient */ - it('Autofocuses first item on click by default', () => { + it('Does not autofocus first item on click by default', () => { cy.get('[data-cy="toggle"]').click(); - cy.get('#first-item').should('be.focused'); + cy.get('#first-item').should('not.be.focused'); cy.get('[data-cy="toggle"]').trigger('keydown', { key: 'Escape' }); }); - it('Does not autofocus first item on click when shouldFocusFirstItemOnOpen is false', () => { - cy.get('[data-cy="no-autofocus-toggle"]').click(); - cy.get('#first-item').should('not.be.focused'); + it('Autofocuses first item on click when shouldFocusFirstItemOnOpen is true', () => { + cy.get('[data-cy="autofocus-toggle"]').click(); + cy.get('#first-item').should('be.focused'); cy.get('[data-cy="toggle"]').trigger('keydown', { key: 'Escape' }); }); }); diff --git a/packages/react-integration/demo-app-ts/src/components/demos/DropdownDemo/DropdownDemo.tsx b/packages/react-integration/demo-app-ts/src/components/demos/DropdownDemo/DropdownDemo.tsx index a9f701b108d..9d3fb458b62 100644 --- a/packages/react-integration/demo-app-ts/src/components/demos/DropdownDemo/DropdownDemo.tsx +++ b/packages/react-integration/demo-app-ts/src/components/demos/DropdownDemo/DropdownDemo.tsx @@ -68,12 +68,12 @@ export const DropdownDemo: React.FunctionComponent = () => { setIsNoAutofocusOpen(isOpen)} onSelect={onNoAutofocusSelect} toggle={(toggleRef) => (