Skip to content

Commit

Permalink
fix(Select/Dropdown): updated autofocus to false by default in v6 (#1…
Browse files Browse the repository at this point in the history
…1115)

* fix(Select/Dropdown): updated autofocus to false by default in v6

* Updated expectation in cypress test
  • Loading branch information
thatblindgeye authored Oct 23, 2024
1 parent 09a8f38 commit 2b2bc35
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 9 deletions.
2 changes: 1 addition & 1 deletion packages/react-core/src/components/Dropdown/Dropdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ const DropdownBase: React.FunctionComponent<DropdownProps> = ({
onOpenChangeKeys = ['Escape', 'Tab'],
menuHeight,
maxMenuHeight,
shouldFocusFirstItemOnOpen = true,
shouldFocusFirstItemOnOpen = false,
...props
}: DropdownProps) => {
const localMenuRef = React.useRef<HTMLDivElement>();
Expand Down
2 changes: 1 addition & 1 deletion packages/react-core/src/components/Select/Select.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ const SelectBase: React.FunctionComponent<SelectProps & OUIAProps> = ({
selected,
toggle,
shouldFocusToggleOnSelect = false,
shouldFocusFirstItemOnOpen = true,
shouldFocusFirstItemOnOpen = false,
onOpenChange,
onOpenChangeKeys = ['Escape', 'Tab'],
isPlain,
Expand Down
10 changes: 5 additions & 5 deletions packages/react-integration/cypress/integration/dropdown.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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' });
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,12 @@ export const DropdownDemo: React.FunctionComponent = () => {
</Dropdown>
<Dropdown
isOpen={isNoAutofocusOpen}
shouldFocusFirstItemOnOpen={false}
shouldFocusFirstItemOnOpen={true}
onOpenChange={(isOpen) => setIsNoAutofocusOpen(isOpen)}
onSelect={onNoAutofocusSelect}
toggle={(toggleRef) => (
<MenuToggle
data-cy="no-autofocus-toggle"
data-cy="autofocus-toggle"
onClick={onNoAutofocusToggleClick}
isExpanded={isNoAutofocusOpen}
ref={toggleRef}
Expand Down

0 comments on commit 2b2bc35

Please sign in to comment.