-
Notifications
You must be signed in to change notification settings - Fork 6.8k
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
autocomplete - HOME and END keys not working #3496
Comments
For reference, POS1 is the Home key on German keyboards. |
+1 As angularjs autocomplete does allow to use these keys on the input, I agree that this should work on this component too. |
* Fixes the autocomplete not scrolling to active items that were highlighted by pressing `home` or `end`. * Switches up the logic to scroll to any newly-focused options. This should make it more future-proof, if we add more shortcuts to the key manager. Relates to angular#3496.
@crisbeto @jelbourn I was looking to implement this, and I think the implementation here should consider the following paths:
Both of these behaviours can be achieved by some conditional tests on the Example (just a simple conditional that may be extracted to a callback):
It'll really be nice if you can offer some guidance on the best way to implement this. |
I've also been looking at this. There is some special handling done in autocomplete-trigger.ts already, so I added a check to see if the panel is actually open and if the shift key is being pressed. In my testing this works pretty intuitively. However, I'm not sure what the desired behavior is if home or end is pressed while the panel is closed. _handleKeydown(event: KeyboardEvent): void {
if (this.activeOption && event.keyCode === ENTER) {
this.activeOption._selectViaInteraction();
event.preventDefault();
} else {
const prevActiveItem = this.autocomplete._keyManager.activeItem;
const isArrowKey = event.keyCode === UP_ARROW || event.keyCode === DOWN_ARROW;
if (isArrowKey) {
this.openPanel();
}
// Only intercept keys if the panel is open and the shift key is not being used.
if (this.panelOpen && !event.shiftKey) {
this.autocomplete._keyManager.onKeydown(event);
}
Promise.resolve().then(() => {
if (isArrowKey || this.autocomplete._keyManager.activeItem !== prevActiveItem) {
this._scrollToOption();
}
});
}
} |
Please don't hijack the HOME and END with any special rules in special cases; simply let them work as they do in normal text editing. I am very used to going back and editing input fields in complex searches, and having that sometimes be "randomly" blocked would be very surprising and frustrating. |
@jonbrock your solution is really good and simple. The only point that I can see that maybe be a problem is that the Of course we can handle this with:
But I don't know if it's a good idea to the autocomplete-trigger to know that much of the implementation of the If the material team think this is ok we can totally go this way. |
What is the default behavior for safari for HOME and END keys? In the angular1 material it is the default behavior as intended for input fields. The browserstack tests are failing for HOME and END keys, therefore their behavior on SAFARI for IOS needs discussion |
… is interacting with the element * Refactors the `ListKeyManager` to only handle the home and end keys after the user has interacted. A list becomes interactive if the previous keypress, that occurred inside it, was handled by the key manager. This allows us to continue supporting skipping to the first/last items with home/end, while also not blocking the default behavior in cases like the select where it can be useful when editing text. * Reworks the Autocomplete, ListKeyManager and ChipList tests to use the `createKeyboardEvent`, instead of making their own fake keyboard events. * Adds a `target` parameter to the `createKeyboardEvent` function, allowing us to define the event target. Fixes angular#3496.
* Removes the handling for the home and end keys from the ListKeyManager since their usage isn't as generic as the arrow keys. * Adds the home and end key handling to the select specifically. * Reworks the Autocomplete, ListKeyManager and ChipList tests to use the `createKeyboardEvent`, instead of making their own fake keyboard events. * Adds a `target` parameter to the `createKeyboardEvent` function, allowing us to define the event target. Fixes angular#3496.
* Removes the handling for the home and end keys from the ListKeyManager since their usage isn't as generic as the arrow keys. * Adds the home and end key handling to the select specifically. * Reworks the Autocomplete, ListKeyManager and ChipList tests to use the `createKeyboardEvent`, instead of making their own fake keyboard events. * Adds a `target` parameter to the `createKeyboardEvent` function, allowing us to define the event target. Fixes angular#3496.
* Removes the handling for the home and end keys from the ListKeyManager since their usage isn't as generic as the arrow keys. * Adds the home and end key handling to the select specifically. * Reworks the Autocomplete, ListKeyManager and ChipList tests to use the `createKeyboardEvent`, instead of making their own fake keyboard events. * Adds a `target` parameter to the `createKeyboardEvent` function, allowing us to define the event target. Fixes angular#3496.
* Removes the handling for the home and end keys from the ListKeyManager since their usage isn't as generic as the arrow keys. * Adds the home and end key handling to the select specifically. * Reworks the Autocomplete, ListKeyManager and ChipList tests to use the `createKeyboardEvent`, instead of making their own fake keyboard events. * Adds a `target` parameter to the `createKeyboardEvent` function, allowing us to define the event target. Fixes #3496.
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. |
Bug, feature request, or proposal:
I would like to use those keys as "normal" to navigate through my input string..
Like "shift + POS1" will select all.. :)
What is the expected behavior?
Maybe behavior of those keys could be configured?!
What is the current behavior?
Key will only be used to navigate through autocomplete-results
What are the steps to reproduce?
.. should be clear ..
What is the use-case or motivation for changing an existing behavior?
Better usability.
If i want to clear an input field, i will always press "shift + pos1" .. but now its not working anymore! =/
I would guess I am not the only one doing it like this..
Which versions of Angular, Material, OS, browsers are affected?
angular4, material.beta2
Is there anything else we should know?
No, thanks! :)
The text was updated successfully, but these errors were encountered: