Skip to content

refactor(mdc-chips): Base isEmptyInput check on chipInput value. #16977

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 9, 2019

Conversation

kor-k
Copy link
Contributor

@kor-k kor-k commented Sep 4, 2019

Ensures that grids using custom input elements don't break on _isEmptyInput checks. (empty() in chip-input.ts uses the same !input.value logic, so there's no change for existing implementations.)

Ensures that grids using custom input elements don't break on _isEmptyInput checks. (empty() in chip-input.ts uses the same !input.value logic, so there's no change for existing implementations.)
@kor-k kor-k requested a review from mmalerba as a code owner September 4, 2019 21:16
@googlebot googlebot added the cla: yes PR author has agreed to Google's Contributor License Agreement label Sep 4, 2019
if (element && element.nodeName.toLowerCase() === 'input') {
let input = element as HTMLInputElement;
return !input.value;
if (element && element.id === this._chipInput!.id) {
Copy link
Member

Choose a reason for hiding this comment

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

I'm not sure why we need this check in the first place. Wouldn't the chip grid always be associated with the proper input anyway because of its DOM structure?

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 method is called in a generic _keyDown handler, so we're attempting to determine first if the element that received the keyDown event is the input element, and second, whether that input is empty.

Copy link
Member

Choose a reason for hiding this comment

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

Makes sense, but it seems a little fragile because it assumes that the input will have an ID. We could check it by identity instead (element === this._chipInput).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The problem there comes that _chipInput is not actually a reference to an html element, it's an interface defined in chip-text-control.ts that's provided to the grid (that provides the necessary references/methods to drive interaction with the input), so the two aren't comparable. For context, _chipInput must always have an id, it's a required field. Inputs that use a matChipInputFor directive have the id generated and assigned automatically. It would be the onus of any person using a custom input to properly implement the interface and assign the id.

Copy link
Member

@crisbeto crisbeto left a comment

Choose a reason for hiding this comment

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

LGTM

@crisbeto crisbeto added P3 An issue that is relevant to core functions, but does not impede progress. Important, but not urgent pr: lgtm action: merge The PR is ready for merge by the caretaker target: patch This PR is targeted for the next patch release labels Sep 6, 2019
@ngbot
Copy link

ngbot bot commented Sep 6, 2019

I see that you just added the pr: merge ready label, but the following checks are still failing:
    failure status "ci/circleci: tests_browserstack" is failing

If you want your PR to be merged, it has to pass all the CI checks.

If you can't get the PR to a green state due to flakes or broken master, please try rebasing to master and/or restarting the CI job. If that fails and you believe that the issue is not due to your change, please contact the caretaker and ask for help.

@jelbourn jelbourn merged commit c881474 into angular:master Sep 9, 2019
@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 Oct 10, 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 P3 An issue that is relevant to core functions, but does not impede progress. Important, but not urgent target: patch This PR is targeted for the next patch release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants