-
Notifications
You must be signed in to change notification settings - Fork 6.8k
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
Conversation
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.)
if (element && element.nodeName.toLowerCase() === 'input') { | ||
let input = element as HTMLInputElement; | ||
return !input.value; | ||
if (element && element.id === this._chipInput!.id) { |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
).
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
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.)