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

Add tab helper (to simulate "tabbing" through focusable elements) #1113

Merged
merged 6 commits into from
Oct 21, 2021

Conversation

NullVoxPopuli
Copy link
Sponsor Collaborator

@NullVoxPopuli NullVoxPopuli commented Aug 24, 2021

Continuation of: https://github.com/emberjs/ember-test-helpers/pull/771/files

Tested Locally:

  • Firefox v91.0.2 on Ubuntu Linux

@Turbo87
Copy link
Member

Turbo87 commented Sep 7, 2021

does this respect the fact that on macOS Chrome only links are tab enabled by default, and links won't receive focus?

@NullVoxPopuli
Copy link
Sponsor Collaborator Author

@Turbo87 I am not sure what you mean? can you describe that behavior? and/or how it's different from other browsers?

Today, I only tested the test suite in Firefox on linux.
If Mac has different behaviors, would you be open to a separate PR that expands the test matrix to include MacOS?

@Turbo87
Copy link
Member

Turbo87 commented Sep 8, 2021

I am not sure what you mean? can you describe that behavior?

on macOS Chrome links are not part of the tab order. in other words: when you press Tab it won't focus links.

and/or how it's different from other browsers?

Firefox on macOS does focus links. Chrome on other platforms AFAIK also focusses links.

@NullVoxPopuli
Copy link
Sponsor Collaborator Author

NullVoxPopuli commented Sep 8, 2021

I can focus links via tab (on Mac, Chrome)
image

but anyway, running the tests in Chrome on Mac still results in a successful test suite.

@Turbo87
Copy link
Member

Turbo87 commented Sep 8, 2021

OMG they finally fixed it 😂

forget everything I said... 🙈

@MelSumner
Copy link
Contributor

@rwjblue I love this, can we have this please? ^_^

Copy link
Contributor

@MelSumner MelSumner left a comment

Choose a reason for hiding this comment

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

I don't think I can officially approve this but 100% I think it's great!

@rwjblue
Copy link
Member

rwjblue commented Sep 14, 2021

I'll try to review in detail this week.

@NullVoxPopuli - Can you use the Co-authored-by: commit header to add attribution for @mogstad's hard work over in #771?

@NullVoxPopuli
Copy link
Sponsor Collaborator Author

sure thing! did I do it right? I've never done a Co-authored by thing

@mogstad
Copy link
Contributor

mogstad commented Sep 15, 2021

Thanks for picking this up NullVoxPopuli, and bringing it over the finish line.

Re Co-authored I usually just includes it at the bottom of the commit body and not in the title.

does this respect the fact that on macOS Chrome only links are tab enabled by default, and links won't receive focus?

This is the default behaviour in Safari on macOS, and there is a setting to change it.. I haven’t found a way of detecting this setting. The code doesn’t try to accommodate for Safari’s behaviour. Detecting Safari and filter out links with a default tabindex should be rather straightforward.

@NullVoxPopuli
Copy link
Sponsor Collaborator Author

Ok, I've fixed the attribution (thanks again, @mogstad !!!)
And I've rebased.

Lemme know if anything needs to be done for this batch of work :)

NullVoxPopuli and others added 2 commits October 6, 2021 15:53
Co-Authored-By: Bjarne Mogstad <me@mogstad.co>
Comment on lines 31 to 39
if (workaroundForIE11) {
let acceptNode = filter ? (filter.acceptNode as any as NodeFilter) : null;
return ownerDocument.createTreeWalker(
root,
whatToShow,
acceptNode,
entityReferenceExpansion
);
} else {
Copy link
Member

Choose a reason for hiding this comment

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

I think we can probably just say that we don't support new features in IE11 mode. What do you think?

Copy link
Sponsor Collaborator Author

Choose a reason for hiding this comment

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

does that require a breaking release of test-helpers?
as long as I can still use this pre-ember 4, I think this sounds great :D

@@ -1,7 +1,7 @@
import isFormControl from './-is-form-control';
import { isDocument, isContentEditable, isWindow } from './-target';

const FOCUSABLE_TAGS = ['A'];
const FOCUSABLE_TAGS = ['A', 'SUMMARY'];
Copy link
Member

Choose a reason for hiding this comment

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

Link to spec suggesting that this is focusable?

Copy link
Sponsor Collaborator Author

Choose a reason for hiding this comment

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

good call, I should probably drop a bunch of spec links in here

Copy link
Sponsor Collaborator Author

Choose a reason for hiding this comment

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

https://html.spec.whatwg.org/multipage/interaction.html#the-tabindex-attribute you may have to ctrl+f to get to it, but this is the nearest anchor/header

addon-test-support/@ember/test-helpers/dom/fire-event.ts Outdated Show resolved Hide resolved
addon-test-support/@ember/test-helpers/dom/tab.ts Outdated Show resolved Hide resolved
Comment on lines 20 to 23
function isVisible(element: Element): boolean {
let styles = window.getComputedStyle(element);
return styles.display !== 'none' && styles.visibility !== 'hidden';
}
Copy link
Member

Choose a reason for hiding this comment

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

Hmm, this seems incomplete to me. 🤔

It could also be positioned outside the viewport, right?

Copy link
Sponsor Collaborator Author

Choose a reason for hiding this comment

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

yeah -- isVisible kinda has multiple meanings. 🤔

as implemented, it's like the real behavior where the tabbable element can be tabbed to even when it's not in the viewport (and normally this scrolls to the element so that it is in the viewport) -- maybe isVisible should be renamed to isVisibleInDOM and a separate isVisibleInViewport should be implemented just to differentiate, even if unused initially?

addon-test-support/@ember/test-helpers/dom/tab.ts Outdated Show resolved Hide resolved
Comment on lines +194 to +195
// needs to be get so prop-paths can be used, such as "target.id"
step += ` ${get(e, prop)}`;
Copy link
Member

Choose a reason for hiding this comment

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

Can we just look for the specfic ones we care about? I'd rather not use Ember.get here...

Copy link
Sponsor Collaborator Author

Choose a reason for hiding this comment

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

thoughts on lodash.get?

Copy link
Contributor

Choose a reason for hiding this comment

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

@NullVoxPopuli what's the decision here?

Copy link
Sponsor Collaborator Author

Choose a reason for hiding this comment

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

gonna leave ember.get, because of the need for nested property path accesses in the tests

tests/unit/dom/tab-test.js Show resolved Hide resolved
tests/unit/dom/tab-test.js Show resolved Hide resolved
Copy link
Contributor

@MelSumner MelSumner left a comment

Choose a reason for hiding this comment

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

Since the concerns seem addressed and the tests are passing, I'm approving this PR so that we can move things forward. Thank you for working on this!

@MelSumner MelSumner merged commit 205dd8e into emberjs:master Oct 21, 2021
@NullVoxPopuli NullVoxPopuli mentioned this pull request Oct 21, 2021
Closed
@rwjblue rwjblue changed the title Tab support Add tab helper (to simulate "tabbing" through focusable elements) Oct 22, 2021
@rwjblue
Copy link
Member

rwjblue commented Oct 25, 2021

Looks like this missed adding registerHooks support. @NullVoxPopuli - would you be able to do that?

@NullVoxPopuli
Copy link
Sponsor Collaborator Author

@rwjblue sure thing -- but for clarification, is registerHooks this: #1142 ?

@scalvert
Copy link
Contributor

It is not. It's #878

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants