Skip to content

fix(chips): default click action on chip being prevented #12856

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

Merged
merged 1 commit into from
Sep 14, 2018

Conversation

crisbeto
Copy link
Member

Fixes all the click actions on a chip being prevented. The action wasn't being prevented up until c82aca9 where it got moved out of the if (this.disabled). Since there isn't any info or tests around why it was done this way, I'm assuming that it was by accident.

Fixes #9032.

@crisbeto crisbeto added P2 The issue is important to a large percentage of users, with a workaround target: patch This PR is targeted for the next patch release labels Aug 27, 2018
@crisbeto crisbeto requested a review from jelbourn as a code owner August 27, 2018 18:15
@googlebot googlebot added the cla: yes PR author has agreed to Google's Contributor License Agreement label Aug 27, 2018
@crisbeto crisbeto force-pushed the 9032/chip-prevent-default branch from a443df6 to 737aec8 Compare August 27, 2018 19:47
Copy link
Member

@jelbourn jelbourn left a comment

Choose a reason for hiding this comment

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

LGTM

@jelbourn jelbourn added pr: lgtm action: merge The PR is ready for merge by the caretaker labels Aug 27, 2018
@crisbeto crisbeto force-pushed the 9032/chip-prevent-default branch from 737aec8 to 812f213 Compare August 28, 2018 20:32
@mbward
Copy link

mbward commented Aug 30, 2018

Looks like the PR branch needs to be re-sync'd to pick up d527e48?

let currentElement = event.target as HTMLElement | null;

while (currentElement && currentElement !== this._elementRef.nativeElement) {
if (currentElement.classList.contains('mat-chip')) {
Copy link
Contributor

Choose a reason for hiding this comment

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

shouldn't we also check if it originates from the chip input?

Copy link
Member Author

Choose a reason for hiding this comment

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

That's not necessary, because the focus method checks whether the input is focused.

@vivian-hu-zz
Copy link
Contributor

When trying to sync this PR into google, I found I need to do the following to make them pass:

  1. revert the change made in src/lib/chips/chip-list.ts
  2. change chip.ts into this:
    _handleClick(event: Event) {
    // Check disabled
    if (this.disabled) {
    event.preventDefault();
    } else {
    event.stopPropagation();
    }
    }

We can take a 2 step approach with the first step just to fix the default event handler bug, and handle the even propagation later since we will need to fix the broken test cases first.

@crisbeto crisbeto force-pushed the 9032/chip-prevent-default branch from 812f213 to bb520e3 Compare September 10, 2018 18:33
@crisbeto
Copy link
Member Author

crisbeto commented Sep 10, 2018

@vivian-hu I've switched it back to always stop propagation. The important change in this PR is that we call preventDefault for disabled chips, I also removed the stopPropagation since it didn't look like there was a particular reason for it.

@crisbeto crisbeto force-pushed the 9032/chip-prevent-default branch from bb520e3 to 289de51 Compare September 10, 2018 18:41
Fixes all the click actions on a chip being prevented. The action wasn't being prevented up until c82aca9 where it got moved out of the `if (this.disabled)`. Since there isn't any info or tests around why it was done this way, I'm assuming that it was by accident.

Fixes angular#9032.
@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Sep 9, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
action: merge The PR is ready for merge by the caretaker cla: yes PR author has agreed to Google's Contributor License Agreement P2 The issue is important to a large percentage of users, with a workaround target: patch This PR is targeted for the next patch release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Chips prevent anchor link navigatation
6 participants