fluentui icon indicating copy to clipboard operation
fluentui copied to clipboard

[Bug]: Combobox - Defaul - Space key clears the combobox input

Open kolaps33 opened this issue 3 years ago • 10 comments

Library

React Components / v9 (@fluentui/react-components)

System Info

System:
    OS: Windows 10 10.0.22621
    CPU: (12) x64 Intel(R) Xeon(R) E-2176M  CPU @ 2.70GHz
    Memory: 12.51 GB / 31.74 GB
  Browsers:
    Edge: Spartan (44.22621.1105.0), Chromium (108.0.1462.76)
    Internet Explorer: 11.0.22621.1

Are you reporting Accessibility issue?

None

Reproduction

https://codesandbox.io/s/7mzpld?file=/example.tsx

Bug Description

Steps:

  1. Navigate to combobox
  2. Type letter "w" or any letter which doesn't match any option in list
  3. press space key

Actual Behavior

it close the list and clear whole input

Expected Behavior

it should not clear what user wrote in input... it sounds buggy... we should investigate what we want to do about list closing, because in this example: https://w3c.github.io/aria-practices/examples/combobox/combobox-autocomplete-list.html they close the list once they don't match the option from the list...

Logs

No response

Requested priority

Normal

Products/sites affected

No response

Are you willing to submit a PR to fix?

no

Validations

  • [X] Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
  • [X] The provided reproduction is a minimal reproducible example of the bug.

kolaps33 avatar Jan 16 '23 07:01 kolaps33

In the UX study on combobox, one of the more interesting results was that people using the keyboard and especially using it with screen readers overwhelmingly expected space to select rather than type, to the extent that the reverse behavior presented an issue. This was true even in freeform cases where the value was expected to contain a string (specifically for a combobox that had names, both first and last). That's why the default behavior is to select with space.

I did actually create a PR to add a prop to override that behavior (https://github.com/microsoft/fluentui/pull/25914), but in chatting with the team, decided to hold off until we got a better feel for the use cases and whether they would be better served by the prop or by recomposition. As a reference, recomposing to allow space would look essentially like this:

const useCustomCombobox = (props, ref) => {
  const state = useCombobox_unstable(props, ref);
  state.input.onKeyDown = React.useCallback((ev) => {
    if (ev.key === ' ') return;
    state.input.onKeyDown(ev);
  });
  return state;
};

const CustomCombobox = React.forwardRef((props, ref) => {
  const state = useCustomCombobox(props, ref);
  const contextValues = useComboboxContextValues(state);

  useComboboxStyles_unstable(state);
  return renderCombobox_unstable(state, contextValues);
});

I'm definitely still looking at whether we should add the allowSpaceAsCharacter out of the box, and specific use cases would help a lot to determine whether that's the right prop and approach to take.

smhigley avatar Feb 08 '23 21:02 smhigley

In freeform, this does not make any sense. free form should allow a user to type whatever they want in the textbox. Not allowing a space is ridiculous in this case.

ParadimeWeb avatar Feb 08 '23 22:02 ParadimeWeb

In the UX study on combobox, one of the more interesting results was that people using the keyboard and especially using it with screen readers overwhelmingly expected space to select rather than type, to the extent that the reverse behavior presented an issue.

@smhigley Wondering how it works for search.... For example, in Teams, I would like to search for "Sarah" and there multiple persons with this name. Without being able to type a surname it might be impossible to select a proper person 🙃

Another example is Google search:

image image

I can't imagine that I will not be able to use a space key there.

layershifter avatar Mar 20 '23 09:03 layershifter

Adding Partber Ask as this also needs to be clarified before Teams starts consuming Combobox.

I understand why users might have liked the possibility to use space to confirm the option. However, it would have been to double check with them, what would be the expectation if any of the options had a space in the name.

In reality, most of the times combobox options come from translations or user data. The developer might not have sufficient information to make a decision if the proposed allowSpaceAsCharacter should or should not be enabled - it might not be necessary for some languages, but might need to be used for other languages.

jurokapsiar avatar Apr 03 '23 06:04 jurokapsiar

I just want to add an additional use case. We're building an address autocomplete and ran into this problem. It's impossible to get an accurate match without the use of "space" characters.

noynek avatar Apr 19 '23 16:04 noynek

If the fluentui team doesn't want to change the default behavior then this is fine for me, but I would really hope to at least get the option to be able to use the alternate behavior which allows entry of spaces.

stefan-schweiger avatar May 02 '23 09:05 stefan-schweiger

FYI, there is a RFC related to this problem, https://github.com/microsoft/fluentui/pull/27700

layershifter avatar May 02 '23 09:05 layershifter

@layershifter thanks for providing the link

in the meantime if anyone needs this ASAP this is the patch I'm using for now:

diff --git a/node_modules/@fluentui/react-combobox/lib-commonjs/utils/dropdownKeyActions.js b/node_modules/@fluentui/react-combobox/lib-commonjs/utils/dropdownKeyActions.js
index 7737ed5..f66a74b 100644
--- a/node_modules/@fluentui/react-combobox/lib-commonjs/utils/dropdownKeyActions.js
+++ b/node_modules/@fluentui/react-combobox/lib-commonjs/utils/dropdownKeyActions.js
@@ -32,7 +32,7 @@ function getDropdownActionFromKey(e, options = {}) {
         return 'None';
     }
     // select or close actions
-    if (code === _keyboardKeys.ArrowUp && altKey || code === _keyboardKeys.Enter || !multiselect && code === _keyboardKeys.Space) {
+    if (code === _keyboardKeys.ArrowUp && altKey || code === _keyboardKeys.Enter) {
         return 'CloseSelect';
     }
     if (multiselect && code === _keyboardKeys.Space) {
diff --git a/node_modules/@fluentui/react-combobox/lib/utils/dropdownKeyActions.js b/node_modules/@fluentui/react-combobox/lib/utils/dropdownKeyActions.js
index 3278839..ef862ea 100644
--- a/node_modules/@fluentui/react-combobox/lib/utils/dropdownKeyActions.js
+++ b/node_modules/@fluentui/react-combobox/lib/utils/dropdownKeyActions.js
@@ -28,7 +28,7 @@ export function getDropdownActionFromKey(e, options = {}) {
     return 'None';
   }
   // select or close actions
-  if (code === keys.ArrowUp && altKey || code === keys.Enter || !multiselect && code === keys.Space) {
+  if (code === keys.ArrowUp && altKey || code === keys.Enter) {
     return 'CloseSelect';
   }
   if (multiselect && code === keys.Space) {

stefan-schweiger avatar May 02 '23 10:05 stefan-schweiger

This bug has been open for 7 months already, is there any plan to get it fixed anytime soon? It looks like there is no momentum on this or the RFC. We've got work pending on it and we'd rather not need to run a package patch if possible

refortie avatar Jul 18 '23 21:07 refortie

pinging as this is blocking me as well from using the combobox properly.

ThomasPe avatar Oct 20 '23 19:10 ThomasPe