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

ComboBox - Scrolls to end of popup when typing #7573

Open
bmingles opened this issue Jan 6, 2025 · 3 comments
Open

ComboBox - Scrolls to end of popup when typing #7573

bmingles opened this issue Jan 6, 2025 · 3 comments
Labels
enhancement New feature or request rsp:ComboBox

Comments

@bmingles
Copy link

bmingles commented Jan 6, 2025

Provide a general summary of the issue here

In certain cases typing in an open ComboBox causes it to scroll to the end of the list.

spectrum-combobox-scroll

🤔 Expected Behavior?

I would expect the ComboBox would scroll to a more intuitive position while typing such as the beginning of the filtered list, the selected item, or no scrolling at all.

😯 Current Behavior

It currently scrolls to the end of the list in certain scenarios (see codesandbox)

💁 Possible Solution

No response

🔦 Context

No response

🖥️ Steps to Reproduce

Code sandbox example

  1. Open ComboBox
  2. Manually scroll to selected "Display 91" item
  3. Backspace the 1 in the search box resulting in "Display 9"
  4. Scroll jumps to end of CombobBox

Version

3.38.0

What browsers are you seeing the problem on?

Chrome

If other, please specify.

No response

What operating system are you using?

MacOS

🧢 Your Company/Team

No response

🕷 Tracking Issue

No response

@LFDanLu
Copy link
Member

LFDanLu commented Jan 8, 2025

Technically the tracked scroll position isn't changing (e.g. scrollTop: 2000), but rather the content size of the list has decreased due to the filtering and thus scrollTop: 2000 is further down the list than before. Perhaps we could instead store a proportional scroll position (e.g. scrollPos = ..5) or reset the scroll position to the top of the list like you suggested. I'll bring this up with the team for discussion

@LFDanLu LFDanLu added enhancement New feature or request rsp:ComboBox labels Jan 8, 2025
@bmingles
Copy link
Author

bmingles commented Jan 8, 2025

@LFDanLu FWIW, changing "Display 91" to "Display 9" increases the content size as opposed to decreasing it.

NVM, disregard. Forgot the initial open is unfiltered. It does decrease the size in the example I provided as you stated.

bmingles added a commit to deephaven/web-client-ui that referenced this issue Jan 9, 2025
DH-18088 & DH-18087: ComboBox now clears search filter when opening the
ComboBox unless it is triggered by user input.

### Testing
- Typing in a combobox should open it filtered by the search text
- Clicking the dropdown should open the CombBox unfiltered
- Typing while open should filter results
> Note that there seems to be a Spectrum bug that can cause some weird
scrolling behavior when typing in an opened ComboBox
adobe/react-spectrum#7573

#### menu_trigger="focus"
- Clicking search input should open it unfiltered

Here's a script with a few different configurations

```python
import deephaven.ui as ui
from deephaven import time_table
import datetime

# Ticking table with initial row count of 200 that adds a row every second
initial_row_count = 200
_table = time_table(
    "PT1S",
    start_time=datetime.datetime.now() - datetime.timedelta(seconds=initial_row_count),
).update(
    [
        "Int=new Integer(i)",
        "Text=new String(`Display `+i)",
    ]
)

item_list = [ui.item(f"Display {i}") for i in range(1, 201)]


# Basic ComboBox
@ui.component
def ui_combo_box_basic():
    value, set_value = ui.use_state("Display 91")

    return ui.combo_box(
        item_list,
        label=f"Basic ({value})",
        selected_key=value,
        on_change=set_value,
        width="size-3000"
    )


# Uncontrolled ComboBox (Table source)
@ui.component
def ui_combo_box_uncontrolled(table):
    value, set_value = ui.use_state("")

    combo1 = ui.combo_box(
        ui.item_table_source(table, key_column="Text", label_column="Text"),
        default_selected_key="Display 92",
        label=f"Uncontrolled Table Source ({value or 'None'})",
        on_change=set_value,
        width="size-3000"
    )

    return combo1


# Controlled ComboBox (Table source)
@ui.component
def ui_combo_box_controlled(table, menu_trigger):
    value, set_value = ui.use_state("Display 93")

    combo1 = ui.combo_box(
        ui.item_table_source(table, key_column="Text", label_column="Text"),
        selected_key=value,
        label=f"Controlled Table Source ({value}) {menu_trigger or ''}",
        menu_trigger=menu_trigger,
        on_change=set_value,
        width="size-3000"
    )

    btn = ui.button("Set Value", on_press=lambda: set_value("Display 104"))

    return combo1, btn


# Controlled input ComboBox (Table source)
@ui.component
def ui_combo_box_input_controlled(table, menu_trigger):
    input_value, set_input_value = ui.use_state("Display 94")
    value, set_value = ui.use_state("Display 94")

    combo1 = ui.combo_box(
        ui.item_table_source(table, key_column="Text", label_column="Text"),
        input_value=input_value,
        on_input_change=set_input_value,
        default_selected_key=value,
        label=f"Controlled Input Table Source ({value}) {menu_trigger or ''}",
        menu_trigger=menu_trigger,
        on_change=set_value,
        width="size-3000"
    )

    btn = ui.button("Set Input", on_press=lambda: set_input_value("Display 104"))

    return combo1, btn

# Layout
@ui.component
def ui_layout():
    return (
        ui_combo_box_basic(),
        ui_combo_box_uncontrolled(_table), 
        ui_combo_box_controlled(_table, None), 
        ui_combo_box_controlled(_table, "focus"),
        ui_combo_box_input_controlled(_table, None),
    )

tests = ui_layout()
```
@LFDanLu
Copy link
Member

LFDanLu commented Jan 9, 2025

Talked with the team, ideally we'd want to do some kind of scroll anchoring where we'd try to bring the previously focused option back into view after the collection changes. If said option no longer exists then we'd reset scroll position to the top of the list.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request rsp:ComboBox
Projects
Status: 🩺 To Triage
Development

No branches or pull requests

2 participants