|
10 | 10 | /// <reference types="cypress-real-events" /> |
11 | 11 | /// <reference types="../../../cypress/support" /> |
12 | 12 |
|
13 | | -import React, { useState } from 'react'; |
| 13 | +import React from 'react'; |
14 | 14 | import { EuiAccordion, EuiAccordionProps } from './index'; |
15 | 15 |
|
16 | 16 | const sharedProps: EuiAccordionProps = { |
@@ -53,59 +53,12 @@ describe('EuiAccordion', () => { |
53 | 53 | }); |
54 | 54 | }); |
55 | 55 |
|
56 | | - describe('focus management', () => { |
57 | | - it('maintains focus when the button is clicked', () => { |
58 | | - cy.realMount(<EuiAccordion {...sharedProps} />); |
59 | | - cy.get('.euiAccordion__button').realClick(); |
60 | | - cy.focused().should('have.class', 'euiAccordion__button'); |
61 | | - }); |
62 | | - |
63 | | - it('maintains focus when the button is pressed', () => { |
64 | | - cy.realMount(<EuiAccordion {...sharedProps} />); |
65 | | - cy.realPress('Tab'); |
66 | | - cy.focused().should('have.class', 'euiAccordion__button'); |
67 | | - cy.focused().contains('Click me to toggle').realPress('Enter'); |
68 | | - cy.focused().should('have.class', 'euiAccordion__button'); |
69 | | - }); |
70 | | - |
71 | | - describe('forceState', () => { |
72 | | - it('does not focus the accordion when `forceState` prevents the accordion from opening', () => { |
73 | | - cy.realMount(<EuiAccordion {...sharedProps} forceState="closed" />); |
74 | | - |
75 | | - cy.contains('Click me to toggle').realClick(); |
76 | | - // cy.focused() is flaky here and doesn't always return an element, so use document.activeElement instead |
77 | | - cy.then(() => { |
78 | | - expect(document.activeElement).not.to.have.class( |
79 | | - 'euiAccordion__childWrapper' |
80 | | - ); |
81 | | - }); |
82 | | - }); |
83 | | - |
84 | | - it('does not focus the accordion when programmatically toggled from outside the accordion', () => { |
85 | | - const ControlledComponent = () => { |
86 | | - const [accordionOpen, setAccordionOpen] = useState(false); |
87 | | - return ( |
88 | | - <> |
89 | | - <button |
90 | | - data-test-subj="toggleForceState" |
91 | | - onClick={() => setAccordionOpen(!accordionOpen)} |
92 | | - > |
93 | | - Control accordion |
94 | | - </button> |
95 | | - <EuiAccordion |
96 | | - {...sharedProps} |
97 | | - forceState={accordionOpen ? 'open' : 'closed'} |
98 | | - /> |
99 | | - </> |
100 | | - ); |
101 | | - }; |
102 | | - cy.realMount(<ControlledComponent />); |
103 | | - |
104 | | - cy.get('[data-test-subj="toggleForceState"]').realClick(); |
105 | | - cy.focused() |
106 | | - .should('not.have.class', 'euiAccordion__childWrapper') |
107 | | - .should('have.attr', 'data-test-subj', 'toggleForceState'); |
108 | | - }); |
109 | | - }); |
| 56 | + // Note: we used to move focus automatically to the accordion contents on open/ |
| 57 | + // toggle button click, but we no longer do so after receiving a11y audit feedback |
| 58 | + // that the change of context was confusing/not helpful |
| 59 | + it('maintains focus on the toggle button when opened', () => { |
| 60 | + cy.realMount(<EuiAccordion {...sharedProps} />); |
| 61 | + cy.get('.euiAccordion__button').realClick(); |
| 62 | + cy.focused().should('have.class', 'euiAccordion__button'); |
110 | 63 | }); |
111 | 64 | }); |
0 commit comments