Skip to content
This repository has been archived by the owner on Apr 12, 2024. It is now read-only.

fix(ngAria.ngClick): restrict preventDefault on space / enter to non-… #16680

Merged
merged 3 commits into from
Sep 6, 2018

Conversation

Narretz
Copy link
Contributor

@Narretz Narretz commented Sep 1, 2018

…interactive elements

Fixes #16664

What kind of change does this PR introduce? (Bug fix, feature, docs update, ...)

What is the current behavior? (You can also link to an open issue here)

What is the new behavior (if this is a feature change)?

Does this PR introduce a breaking change?

Please check if the PR fulfills these requirements

  • The commit message follows our guidelines
  • Fix/Feature: Docs have been added/updated
  • Fix/Feature: Tests have been added; existing tests pass

Other information:

browserTrigger(interactiveElement, 'keydown', {cancelable: true, bubbles: true, keyCode: 13});
browserTrigger(interactiveElement, 'keydown', {cancelable: true, bubbles: true, keyCode: 32});

expect(clickEvents).toEqual([elementType.toLowerCase() + '(false)', elementType.toLowerCase() + '(false)']);
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 the test would be a bit clearer if you checked clickEvents after each browserTrigger.
Otherwise someone might read this test as "you need to trigger two keydowns to get any events".

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, updated

@Narretz
Copy link
Contributor Author

Narretz commented Sep 3, 2018

Reminder: I pushed the branch to this repo, should delete it after merging

Copy link
Member

@gkalpak gkalpak left a comment

Choose a reason for hiding this comment

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

Some minor comments. LGTM otherwise 👍

function createHTML(type) {
var html = '<' + type + '>';

if (type === 'INPUT' || 'TYPE' === 'A') return html;
Copy link
Member

Choose a reason for hiding this comment

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

The 'TYPE' === 'A' part seems fishy 😛

Copy link
Contributor

Choose a reason for hiding this comment

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

🙀

event.preventDefault();
// Prevent the default browser behavior (e.g. scrolling when pressing spacebar) ...
if (nodeBlackList.indexOf(event.target.nodeName) === -1) {
// ... but only when the event is triggered by a non-interactive element
Copy link
Member

Choose a reason for hiding this comment

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

Nit: I would actually flip the last two comments around:

// If the event is triggered on a non-interactive element...
if (...) {
  // ...prevent the default browser behavior...
  ...

if (type === 'INPUT' || 'TYPE' === 'A') return html;

return html + '</' + type + '>';
return '<' + type + '></' + type + '>';
Copy link
Member

Choose a reason for hiding this comment

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

<input></input> is not correct, but will work nonetheless 😃

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, I simply removed it because the browsers don't care ;)

@Narretz Narretz merged commit 8082d5e into master Sep 6, 2018
Narretz added a commit that referenced this pull request Sep 6, 2018
@gkalpak
Copy link
Member

gkalpak commented Sep 6, 2018

For future reference, this fixes a regression introduced in #16604.

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

Successfully merging this pull request may close these issues.

Can't write space chars in input when it in tag with ng-click with ngAria since 1.7.3
4 participants