Skip to content
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

Merged
merged 6 commits into from
Jun 15, 2022

Conversation

davismcphee
Copy link
Contributor

Summary

This PR adds support for focusing on the h1 element when navigating to Discover.

Resolves #133277.

Checklist

For maintainers

function mountComponent(
indexPattern: DataView,
prevSidebarClosed?: boolean,
mountOptions: { attachTo?: HTMLElement } = {}
Copy link
Contributor Author

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.

@davismcphee davismcphee self-assigned this Jun 8, 2022
@davismcphee davismcphee added Feature:Discover Discover Application Team:DataDiscovery Discover, search (e.g. data plugin and KQL), data views, saved searches. For ES|QL, use Team:ES|QL. release_note:enhancement auto-backport Deprecated - use backport:version if exact versions are needed v8.4.0 labels Jun 8, 2022
@davismcphee
Copy link
Contributor Author

@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!

@1Copenut
Copy link
Contributor

1Copenut commented Jun 8, 2022

@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 TAB after the H1 receives focus, we want to let it move to the next natively focusable element. If that's the field search in the sidebar, that input will announce itself to the screen reader.

I took a look at a cloud 7.16.3 instance and mapped the H1 and where focus would go on next TAB keypress. I'll verify this with the local build of latest main branch, and update my image if something has changed.


Screen Shot 2022-06-08 at 4 19 10 PM

@@ -236,7 +241,13 @@ export function DiscoverLayout({
spaces={spaces}
history={history}
/>
<h1 id="savedSearchTitle" className="euiScreenReaderOnly">
<h1
Copy link
Member

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.

Copy link
Contributor

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.


Screen Shot 2022-06-09 at 8 47 53 AM

Copy link
Member

@kertal kertal Jun 9, 2022

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)

@davismcphee
Copy link
Contributor Author

@1Copenut @kertal Thank you both for the confirmation and suggestions. I agree the suggested h1 placement make sense. I'll update the PR to include the new h1 position and mark as ready for review.

@@ -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', () => {
Copy link
Contributor Author

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?

Copy link
Contributor

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();
Copy link
Contributor Author

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.

Copy link
Contributor

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.

Copy link
Contributor Author

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.

@davismcphee davismcphee marked this pull request as ready for review June 14, 2022 01:44
@davismcphee davismcphee requested a review from a team as a code owner June 14, 2022 01:44
@elasticmachine
Copy link
Contributor

Pinging @elastic/kibana-data-discovery (Team:DataDiscovery)

Copy link
Contributor

@jughosta jughosta left a 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', () => {
Copy link
Contributor

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');
Copy link
Contributor

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?

Copy link
Contributor Author

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();
Copy link
Contributor

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.

@davismcphee
Copy link
Contributor Author

Works as expected in Chrome and Firefox but for some reason in Safari it selects the search input after TAB.

@jughosta It looks like by default in Safari you have to use ⌥ + Tab to tab through all focusable elements in the page. Otherwise you can change the default setting with Safari > Preferences > Advanced > Press Tab to highlight each item on a webpage. These solutions fixed the issue for me. Can you confirm one of them fixes it for you as well?

@jughosta
Copy link
Contributor

These solutions fixed the issue for me. Can you confirm one of them fixes it for you as well?

Yes, I can confirm that it makes the focus behave as in other browsers. TIL, thanks!

@davismcphee
Copy link
Contributor Author

Updated with suggestions

@kibana-ci
Copy link
Collaborator

💚 Build Succeeded

Metrics [docs]

Async chunks

Total size of all lazy-loaded chunks that will be downloaded as the user navigates the app

id before after diff
discover 485.6KB 485.8KB +172.0B

History

To update your PR or re-run it, just comment with:
@elasticmachine merge upstream

cc @davismcphee

Copy link
Contributor

@jughosta jughosta left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks 👍

@kertal
Copy link
Member

kertal commented Jun 15, 2022

These solutions fixed the issue for me. Can you confirm one of them fixes it for you as well?

Yes, I can confirm that it makes the focus behave as in other browsers. TIL, thanks!

+1 for TIL! thx!

@kertal
Copy link
Member

kertal commented Jun 15, 2022

We should apply the same pattern when using

  • Surrounding documents
  • Single document
    (in follow up PRs)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
auto-backport Deprecated - use backport:version if exact versions are needed backport:skip This commit does not require backporting Feature:Discover Discover Application release_note:enhancement Team:DataDiscovery Discover, search (e.g. data plugin and KQL), data views, saved searches. For ES|QL, use Team:ES|QL. v8.4.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Discover] Add focus to h1 element when client side routing is executed
7 participants