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

fix: ComboBox show all items on open #2328

Merged
merged 7 commits into from
Jan 9, 2025

Conversation

bmingles
Copy link
Contributor

@bmingles bmingles commented Jan 2, 2025

DH-18088 & DH-18087: ComboBox now clears search filter when opening the ComboBox unless it is triggered by user input.

Testing

menu_trigger="focus"

  • Clicking search input should open it unfiltered

Here's a script with a few different configurations

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()

@bmingles bmingles changed the title WIP: ComboBox show all items on open (DH-18088) fix: ComboBox show all items on open Jan 3, 2025
@bmingles bmingles marked this pull request as ready for review January 3, 2025 16:58
Copy link

codecov bot commented Jan 3, 2025

Codecov Report

Attention: Patch coverage is 11.76471% with 15 lines in your changes missing coverage. Please review.

Project coverage is 46.69%. Comparing base (ca5f6cd) to head (733a315).
Report is 4 commits behind head on main.

Files with missing lines Patch % Lines
...ackages/jsapi-components/src/spectrum/ComboBox.tsx 0.00% 15 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2328      +/-   ##
==========================================
- Coverage   46.71%   46.69%   -0.02%     
==========================================
  Files         704      704              
  Lines       39010    39045      +35     
  Branches     9747     9756       +9     
==========================================
+ Hits        18223    18234      +11     
- Misses      20776    20800      +24     
  Partials       11       11              
Flag Coverage Δ
unit 46.69% <11.76%> (-0.02%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@bmingles bmingles marked this pull request as draft January 3, 2025 20:23
@bmingles bmingles marked this pull request as ready for review January 6, 2025 20:59
@bmingles bmingles requested a review from mofojed January 6, 2025 20:59
@@ -10,7 +10,7 @@ import type { NormalizedItem } from '../utils';
import { type PickerPropsT, usePickerProps } from '../picker';

export type ComboBoxProps = PickerPropsT<SpectrumComboBoxProps<NormalizedItem>>;

export { type MenuTriggerAction } from '@react-types/combobox';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Aside - not our naming, but I was worried this name would conflict with something from the @react-types/menu package. But there they have MenuTriggerType.
I don't know why they didn't call this ComboBoxTriggerType or something instead, but whatever.

// input.
else {
onSearchTextChange('');
inputValueRef.current = value;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this be set in all cases? Everything else looks good.

Copy link
Contributor Author

@bmingles bmingles Jan 9, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm on the fence on this one. My reasoning for only putting it here was that the only consumer should be the menuTrigger === 'input' case in onOpenChange which should only follow this else case. I was trying to conceptually couple them in an attempt to make the code easier to reason about. That said, there's probably not any harm in setting it for all cases, and there could be an edge case that needs it that I'm unaware of. In general, reasoning about the relationship of these 2 functions is a bit of a pain.

@bmingles bmingles merged commit c08bb7b into deephaven:main Jan 9, 2025
15 checks passed
@bmingles bmingles deleted the DH-18088_combo-box-open branch January 9, 2025 21:00
@github-actions github-actions bot locked and limited conversation to collaborators Jan 9, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants