Skip to content

focus container on page load#116

Merged
nolanlawson merged 4 commits into
nolanlawson:masterfrom
mlcdf:focus-container-on-page-load
Apr 17, 2018
Merged

focus container on page load#116
nolanlawson merged 4 commits into
nolanlawson:masterfrom
mlcdf:focus-container-on-page-load

Conversation

@mlcdf

@mlcdf mlcdf commented Apr 14, 2018

Copy link
Copy Markdown
Contributor

On page load, the focus is set the main content area instead of on the nav bar.

This fixes (#99).

@nolanlawson

Copy link
Copy Markdown
Owner

Hmm, it looks like this is failing the tests because it will change the focus anytime Layout.html is created, which basically means anytime we navigate between different pages. In some cases we want the focus to be something else (e.g. you click a toot, you navigate from a timeline view to a thread view, you press the back button, and now you're still focused on the toot).

Is there a way to do this without JavaScript? If not, maybe the most practical thing is to put the focus() in main.js so that it only runs only when the very first page is loaded, and not during in-app navigations.

@mlcdf

mlcdf commented Apr 15, 2018

Copy link
Copy Markdown
Contributor Author

Oh, I see. I'll look into that.

@nolanlawson

Copy link
Copy Markdown
Owner

Another option: I just added a change to LazyPage.html (which loads for all routes) to detect first load versus every subsequent load. We could use the same trick in Layout.html.

I may be best to do this in Layout.html because we don't even need to call querySelectorAll('.container'): you can use ref:node and then this.refs.node in Svelte to get the node of a rendered element.

@mlcdf

mlcdf commented Apr 16, 2018

Copy link
Copy Markdown
Contributor Author

Thanks for the lead on this. Now, I'll try to make this work!

@nolanlawson

Copy link
Copy Markdown
Owner

That's odd; the code looks correct to me but some tests are failing. I'll look into this when I get a chance!

@mlcdf

mlcdf commented Apr 17, 2018

Copy link
Copy Markdown
Contributor Author

I tried to reproduce those failing tests locally, and it worked (it produced the expected result). So, I'm kinda lost on this one.

@nolanlawson

nolanlawson commented Apr 17, 2018

Copy link
Copy Markdown
Owner

Hmmm, I can reproduce using Chrome on Mac with the command:

npx testcafe --hostname localhost chrome --skip-js-errors tests/spec/010-focus.js

Oddly though I can't reproduce manually when using Chrome. It seems there may be some timing issue in a11y-dialog that causes it to think the previous focused element was .container rather than the .play-video-button (when clicking that button).

@nolanlawson

Copy link
Copy Markdown
Owner

^ I couldn't push to your branch for some reason, here's my attempted fix

@nolanlawson nolanlawson merged commit eef54e9 into nolanlawson:master Apr 17, 2018
@mlcdf

mlcdf commented Apr 17, 2018

Copy link
Copy Markdown
Contributor Author

Thank you for the support @nolanlawson!

@mlcdf mlcdf deleted the focus-container-on-page-load branch April 17, 2018 20:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants