-
-
Notifications
You must be signed in to change notification settings - Fork 32.4k
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] Add option to disable handling of home/end #19500
Comments
The current behavior originates from the recommendations of WAI-ARIA authoring practices. However, they make it optional:
https://www.w3.org/TR/wai-aria-practices-1.1/#listbox-popup-keyboard-interaction. So I would suggest
|
If one were to add an option to control this behavior, what would one call such a thing? All of my ideas feel rather verbose. But as to the last line i wrote above. Couldn't you kinda assume that if the shift key is being held, keypresses of home/end/up/down should go to the input field? |
Well, it doesn't have to necessarily be a prop. For instance, it could be a keyboard event handler that set |
Right, that could work too. I guess for now I'll handle it in a custom |
That's a misleading name. We specifically want to tell the component to not handle it. We can't use |
Here is a prior-work with the event flag approach. A user could listen to the event before the component, flag the event as already handled so the component can ignore it. However, it's only one of the options available, it might not be the best one. |
I have added the |
What do you think about this implementation ? index 2c33f552c..107820faf 100644
--- a/packages/material-ui-lab/src/useAutocomplete/useAutocomplete.d.ts
+++ b/packages/material-ui-lab/src/useAutocomplete/useAutocomplete.d.ts
@@ -1,5 +1,10 @@
import * as React from 'react';
+
+export interface KeyDownOrder {
+ [key: string]: KeyDownOrderEvent[],
+}
+
export interface CreateFilterOptionsConfig<T> {
ignoreAccents?: boolean;
ignoreCase?: boolean;
@@ -198,8 +203,20 @@ export interface UseAutocompleteCommonProps<T> {
* It helps the user clear the selected value.
*/
selectOnFocus?: boolean;
+ /**
+ * It establish the execution order of key-down events.
+ * For every key name you can pass an array with no more than two values.
+ * If the array is empty the event is skipped,
+ * Otherwise the events callback are fired following the order.
+ * If you want you can manage the event by your own by simple pass 'own' in the array
+ *
+ * @param {object} execution order of key down event
+ */
+ keyDownOrder?: KeyDownOrder
}
+export type KeyDownOrderEvent = "default" | "own";
+
export type AutocompleteHighlightChangeReason = 'keyboard' | 'mouse' | 'auto';
export type AutocompleteChangeReason = |
I came back to the use case of @mvestergaard, we have recently better organized the documentation to split the @marcosvega91 I don't understand what I'm looking at. Why does it concern the filtering? |
Ok, my bad, the issue is that Material-UI prevent default the native behavior when |
We very likely need to make a change to account for it, it breaks the default behavior. We could either continue in the direction we have started with The alternative is to say, 3 cases are enough, let's wrap all these concerns into a dedicated abstraction. I don't know, I think that I'm more in favor of |
I was referencing to this issue and #19887
And when the keydown is pressed with home key only the onKeyDown callback passed by the user is fired. I can
In this case no callback is fired. Or In this case the callback passed by the user is fired before the original ones. I don't know if it makes sense |
@marcosvega91 Ok, let's move to #19887. For this one, I think that we have a compelling motivation to make a dedicated prop for it. |
Summary 💡
This is merely a suggestion, which I want to gauge the response to.
In some cases, it is not very nice that home/end navigates the options, rather than allowing navigation of the input field. For example, my use case it to use Autocomplete as the basis for a search field.
#18338 fixed a bug where you couldn't use home/end even when the popup isn't open, but what I'm suggesting goes further than that. It would be to add an option that disables the handling of home/end always.
Examples 🌈
N/A
Motivation 🔦
While typing in the field, you may want to quickly start over. For many users
clearOnEscape
isn't the most intuitive for that. I personally tend to do shift+home and then start typing again.Or perhaps a new option isn't even needed, and it should just ignore home/end/up/down when shift is being held?
The text was updated successfully, but these errors were encountered: