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

[FEATURE] On press ESC only empty search field #231

Closed
nischi opened this issue May 26, 2020 · 6 comments · Fixed by #237
Closed

[FEATURE] On press ESC only empty search field #231

nischi opened this issue May 26, 2020 · 6 comments · Fixed by #237

Comments

@nischi
Copy link
Contributor

nischi commented May 26, 2020

It would be very nice to empty the search input with pressing "ESC". But it will close the Dropdown (also happen in your example). Maybe add an option to do this?

Please add an input which handle this feature. Ex. [emptySearchOnEsc]="false".

It could also be that the current behavior is a bug, but maybe some like it to close on ESC some like it to clear out the search box.
Alternative could be to clear out the input on ESC and if the input is empty and you click ESC it will close. So you have both.

I tried to stopPropagation of the event, but it seems that this component add an event handler on body, but didn't find anything in code.

@macjohnny
Copy link
Member

hi @nischi

would you like to file a PR that implements this feature?
currently, keyboard events are handled here:

/**
* Handles the key down event with MatSelect.
* Allows e.g. selecting with enter key, navigation with arrow keys, etc.
* @param event
*/
_handleKeydown(event: KeyboardEvent) {
// Prevent propagation for all alphanumeric characters in order to avoid selection issues
if ((event.key && event.key.length === 1) ||
(event.keyCode >= A && event.keyCode <= Z) ||
(event.keyCode >= ZERO && event.keyCode <= NINE) ||
(event.keyCode === SPACE)
|| (this.preventHomeEndKeyPropagation && (event.keyCode === HOME || event.keyCode === END))
) {
event.stopPropagation();
}
}

@nischi
Copy link
Contributor Author

nischi commented Jun 2, 2020

Will have a look into it.

@ThanosAlmighty
Copy link

Since the search input is tied to a control, it seems easier to just implement yourself @nischi. Why not create your own listener that's active when you focus the search or even the full dropdown control?

@nischi
Copy link
Contributor Author

nischi commented Jun 9, 2020

I tried this, but i can't stop the other listener on the Input, My listener will run after the other and so i can't stop bubbling.

@ThanosAlmighty
Copy link

Oh, I understand. This may not be a problem with this module, rather with the native html dropdown interface.

@nischi
Copy link
Contributor Author

nischi commented Jun 15, 2020

You got have a pull request :)

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

Successfully merging a pull request may close this issue.

3 participants