Terminal.Gui icon indicating copy to clipboard operation
Terminal.Gui copied to clipboard

ComboBox inconsistently clearing text when not matched in listbox

Open tznind opened this issue 2 years ago • 15 comments

Describe the bug There is a wierd bug with ComboBox where typing text into the box that does not appear in its Source gets cleared when you leave the control. The issue goes away if you open then collapse the listbox first.

To Reproduce Steps to reproduce the behavior:

  1. Run ComboBoxIteration Scenario
  2. Type into the ComboBox "hey there"
  3. Press tab
  4. See error: text is cleared

Workaround:

  1. Run ComboBoxIteration Scenario
  2. Expand then collapse the ComboBox manually with mouse
  3. Type into the ComboBox "hey there"
  4. Press tab
  5. Now the text is not cleared

Expected behavior Text should not be cleared upon leaving the combo box.

Screenshots ComboBoxClearing

Desktop (please complete the following information):

  • OS: Windows
  • Shell: Powershell

tznind avatar May 10 '22 08:05 tznind

There is many situations where we want a read only combo box and in this cases must not allowing adding more items to the source.

BDisp avatar May 10 '22 10:05 BDisp

At the moment though the behaviour is inconsistent.

If you toggle the dropdown with the mouse then it doesn't force the Text to match the list. While if you don't toggle the list it does force the Text to match.

I guess there are 2 questions here:

  1. Is it supposed to clear it or not?
  2. Why does not not clear it if you toggle the dropdown down/up with mouse first

tznind avatar May 10 '22 10:05 tznind

Yes, I know it is inconsistent and should be corrected. I just wanted to draw attention to this detail. The author of this control just intended to create a search box when typing in TextField, such as the AutoComplete, and I proposed that it could be transformed into a Combobox, so it is still inconsistent. Therefore, any improvement that can be done only brings benefits.

I guess there are 2 questions here:

1. Is it supposed to clear it or not?

If it's a read only and the typed text does not matching the source then should clear. If match then it must show the equivalents. If not read only then the text typed can stay in the TextField and if needed to add to the source then must have an action by the developer to do the addition.

2. Why does not not clear it if you toggle the dropdown down/up with mouse first

Must have the same behavior as 1.

BDisp avatar May 10 '22 11:05 BDisp

If it's a read only and the typed text does not matching the source then should clear.

How do you control if a ComboBox is 'read only'? Or are you talking about the way we want it to be rather than how it currently is?

tznind avatar May 10 '22 11:05 tznind

How do you control if a ComboBox is 'read only'. Or are you talking about the way we want it to be rather than how it currently is?

That is. There is a ReadOnly property on the ComboBox that don't allow typing, I think, but the user may want to type to search for it. It's complicated :-)

BDisp avatar May 10 '22 11:05 BDisp

Ok cool. Thanks for explaining.

In the interests of documenting the current system state. My current workaround to force the combo box not to clear search is just to toggle the box open/collapse manually in code.

var expand = typeof(ComboBox).GetMethod("Expand");
var collapse = typeof(ComboBox).GetMethod("Collapse");
expand.Invoke(combo, new object[0]);
collapse.Invoke(combo,new object[0]);

For personal preference I also like setting up this keybinding which makes the interaction feel more natural:

combo.AddKeyBinding(Key.CursorDown, Command.Expand);

tznind avatar May 10 '22 12:05 tznind

For personal preference I also like setting up this keybinding which makes the interaction feel more natural:

combo.AddKeyBinding(Key.CursorDown, Command.Expand);

Does this not will conflict with the AddKeyBinding (Key.CursorDown, Command.LineDown);?

BDisp avatar May 10 '22 12:05 BDisp

Does this not will conflict with the AddKeyBinding (Key.CursorDown, Command.LineDown);?

It doesn't seem to. New keybindings overwrite old ones so theres no Exception. And I think because the input focus changes on Expand to the listbox it all just seems to work (i.e. it doesn't break up/down).

tznind avatar May 10 '22 12:05 tznind

It doesn't seem to. New keybindings overwrite old ones so theres no Exception. And I think because the input focus changes on Expand to the listbox it all just seems to work (i.e. it doesn't break up/down).

Ah right, it will change the focus to the ListView and are this view that will handle it, thanks for the clarification.

BDisp avatar May 10 '22 12:05 BDisp

@tznind, @tig I think the ComboBox should always clear if the typed text doesn't exist on the source.

combobox-clear

If the ComboBox is open by F4 or mouse the ListView will always be focused and the first item or the selected item will be the current, updating the search text through the SelectedItemChanged event when cursor keys are used. Pressing Key.Escape undoes the changes and close the ListView.

combobox-open

Typing the exactly text or navigation through cursor to the item, pressing Key.Enter or tabbing will accept the change.

combobox-accept-leave

If ReadOnly is enabled only the first letter will be used on search.

combobox-readonly

This is the iteration with a already selected item:

combobox-iteration

This is a ComboBox alone in a Dialog as the author initially created and it never isn't auto hide. I want to ask if is this to maintain or not?

combobox-dialog

The ListView shouldn't be a subview of ComboBox , but be subview of Application.Top to allow the drop-down always visible even if not fit the superview of the ComboBox . Here a reason why it should:

combobox-window

I'm still working on this but i need answers to my questions above, please. I think the ComboBox alone in a Dialog can be dropped, because it will be unused, I think.

BDisp avatar Mar 22 '23 17:03 BDisp

@tznind, @tig which ColorScheme do you prefer, 1 or 2? 1: imagem 2: imagem

I vote for 1.

BDisp avatar Mar 24 '23 23:03 BDisp

1 does have more visual distinction and would look better on Dialogs where the background is grey by default. So yeah I agree 1.

tznind avatar Mar 25 '23 08:03 tznind

@tznind, @tig I think the ComboBox should always clear if the typed text doesn't exist on the source.

I think this needs a setting e.g. DropDownStyle in WinForms:

We should distinguish visually the two also. If the user cannot enter any text then the text box should not recieve focus (only the list should get focused) and should be grey.

DropDown 1 Specifies that the list is displayed by clicking the down arrow and that the text portion is editable. This means that the user can enter a new value and is not limited to selecting an existing value in the list. When using this setting, the Append value of AutoCompleteMode works the same as the SuggestAppend value. This is the default style.
DropDownList 2 Specifies that the list is displayed by clicking the down arrow and that the text portion is not editable. This means that the user cannot enter a new value. Only values already in the list can be selected. The list displays only if AutoCompleteMode is Suggest or SuggestAppend.

For reference:

image A ComboBox where the options are fixed and you cannot type anything

image A ComboBox where you can type anything

I achieved a similar effect using Menu but that was a bit of a hack:

image

There are many cases where you want the user to be able to enter their own value e.g.

image User can enter any link they want

image User could enter 7.5pt if they wanted

But likewise there are cases where you don't want the user to be able to select any option:

image User can only pick from the selection

I'm still working on this but i need answers to my questions above, please. I think the ComboBox alone in a Dialog can be dropped, because it will be unused, I think.

Thanks for looking into this! I know we can make an awesome view here.

tznind avatar Mar 25 '23 09:03 tznind

I'm still working on this but i need answers to my questions above, please. I think the ComboBox alone in a Dialog can be dropped, because it will be unused, I think.

Thanks for looking into this! I know we can make an awesome view here.

@tznind thanks for your reply. I'm really thinking about replacing the ComboBox alone in a Dialog with the Simple of the ComboBoxStyle:

Simple 0 Specifies that the list is always visible and that the text portion is editable. This means that the user can enter a new value and is not limited to selecting an existing value in the list.

In this case the drop down list will be a subview of the ComboBox and will always visible and it must positioned in a way that it must fit the ComboBox dimensions, like the Dialog, but without it. What do you think?

BDisp avatar Mar 25 '23 11:03 BDisp

Was this fixed recently with the ComboBox PRs? If so, please close.

tig avatar Jan 19 '24 16:01 tig