-
Notifications
You must be signed in to change notification settings - Fork 8.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Discover] Added focus to h1 element when client side routing is executed #133846
[Discover] Added focus to h1 element when client side routing is executed #133846
Conversation
function mountComponent( | ||
indexPattern: DataView, | ||
prevSidebarClosed?: boolean, | ||
mountOptions: { attachTo?: HTMLElement } = {} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
toHaveFocus
doesn't work without the component being mounted to an element in the body, so I added mountOptions
to pass in a mount point.
@1Copenut This PR adds support for focusing on the h1 when navigating to Discover. Based on this comment on the issue, can you confirm whether or not this work is still necessary? If it is, another question: After focusing on the h1 and pressing tab, the field search in the sidebar gains focus. Is this acceptable or should another element gain focus? Thanks! |
@davismcphee Yes, please proceed forward with this improvement. The EUI team is exploring a live region solution but it may not work at Kibana scale and we do not want to block your team from implementing an a11y solution. If users press I took a look at a cloud 7.16.3 instance and mapped the H1 and where focus would go on next |
@@ -236,7 +241,13 @@ export function DiscoverLayout({ | |||
spaces={spaces} | |||
history={history} | |||
/> | |||
<h1 id="savedSearchTitle" className="euiScreenReaderOnly"> | |||
<h1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we could think of moving the <h1>
to L223, so it's the first after the TopNavMemoized. Because when using tab currently the side bar field search gets focus. I think starting with the data view picker would be a better fit.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@kertal Great call. If the H1 can be moved to this new position, it would be a good reference point for future applications. We could use this as guidance to say "Pages and applications should have an H1 just after the memoized top navigation" as common guidance.
I'm attaching a screenshot I took from my local machine this morning with annotations to make sure I'm understanding the new location as you've described it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, that's what I meant and also it works when doing it that way (short local test with Davis PR)
…al tests for Discover accessibility
@@ -174,6 +179,17 @@ describe('Discover component', () => { | |||
expect(component.find('[data-test-subj="discoverChartOptionsToggle"]').exists()).toBeTruthy(); | |||
}); | |||
|
|||
test('the saved search title h1 gains focus on navigate', () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@kertal I added some functional tests for accessibility which make this test sort of redundant. Do you think I should rollback changes to this test file or keep it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's fine to keep it as a unit test too
describe('discover functionality tests', () => { | ||
before(async function () { | ||
await setUpDiscoverPage(); | ||
await PageObjects.timePicker.setDefaultAbsoluteRange(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This call before each test caused my accessibility tests to fail since it changes the initial focus in the browser. To fix this I broke the tests up into 'accessibility tests' and 'functionality tests' so I could skip running this function in the before hook. I'm open to any suggestions about a better way to handle this though.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could also move "discover accessibility tests" out to a new separate file and don't make this file even more complex.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good idea, I'll pull these into a separate _discover_accessibility.ts
file and update the PR.
Pinging @elastic/kibana-data-discovery (Team:DataDiscovery) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Works as expected in Chrome and Firefox but for some reason in Safari it selects the search input after TAB.
@@ -174,6 +179,17 @@ describe('Discover component', () => { | |||
expect(component.find('[data-test-subj="discoverChartOptionsToggle"]').exists()).toBeTruthy(); | |||
}); | |||
|
|||
test('the saved search title h1 gains focus on navigate', () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's fine to keep it as a unit test too
after(tearDownDiscoverPage); | ||
|
||
it('should give focus to the saved search title h1 on navigate', async () => { | ||
const skipButton = await testSubjects.find('discoverSavedSearchTitle'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe titleElement
instead of skipButton
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree, I borrowed this from another test and forgot to update the variable name. Will do that as well.
describe('discover functionality tests', () => { | ||
before(async function () { | ||
await setUpDiscoverPage(); | ||
await PageObjects.timePicker.setDefaultAbsoluteRange(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could also move "discover accessibility tests" out to a new separate file and don't make this file even more complex.
@jughosta It looks like by default in Safari you have to use |
Yes, I can confirm that it makes the focus behave as in other browsers. TIL, thanks! |
Updated with suggestions |
💚 Build SucceededMetrics [docs]Async chunks
History
To update your PR or re-run it, just comment with: cc @davismcphee |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thanks 👍
+1 for TIL! thx! |
We should apply the same pattern when using
|
Summary
This PR adds support for focusing on the h1 element when navigating to Discover.
Resolves #133277.
Checklist
Any text added follows EUI's writing guidelines, uses sentence case text and includes i18n supportDocumentation was added for features that require explanation or tutorialsAny UI touched in this PR is usable by keyboard only (learn more about keyboard accessibility)Any UI touched in this PR does not create any new axe failures (run axe in browser: FF, Chrome)If a plugin configuration key changed, check if it needs to be allowlisted in the cloud and added to the docker listThis renders correctly on smaller devices using a responsive layout. (You can test this in your browser)For maintainers