Skip to content

Commit 9eb128d

Browse files
feat(ui5-multi-combobox): filtering selection enhancement (#12799)
1 parent 5111ce7 commit 9eb128d

File tree

3 files changed

+130
-0
lines changed

3 files changed

+130
-0
lines changed

packages/main/cypress/specs/MultiComboBox.mobile.cy.tsx

Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -570,6 +570,130 @@ describe("Items selection", () => {
570570
.find<ResponsivePopover>("[ui5-responsive-popover]")
571571
.ui5ResponsivePopoverOpened();
572572
});
573+
574+
it("Should disable the toggle button when there are no selected items", () => {
575+
cy.mount(
576+
<MultiComboBox>
577+
<MultiComboBoxItem text="Cosy"></MultiComboBoxItem>
578+
<MultiComboBoxItem text="Compact"></MultiComboBoxItem>
579+
</MultiComboBox>
580+
);
581+
582+
cy.get("[ui5-multi-combobox]")
583+
.realClick();
584+
585+
cy.get("[ui5-multi-combobox]")
586+
.shadow()
587+
.find<ResponsivePopover>("[ui5-responsive-popover]")
588+
.as("respPopover")
589+
.ui5ResponsivePopoverOpened();
590+
591+
cy.get("@respPopover")
592+
.find("[ui5-toggle-button]")
593+
.should("have.attr", "disabled");
594+
});
595+
596+
it("Should enable the toggle button when there is selected item", () => {
597+
cy.mount(
598+
<MultiComboBox>
599+
<MultiComboBoxItem text="Cosy" selected></MultiComboBoxItem>
600+
<MultiComboBoxItem text="Compact"></MultiComboBoxItem>
601+
</MultiComboBox>
602+
);
603+
604+
cy.get("[ui5-multi-combobox]")
605+
.realClick();
606+
607+
cy.get("[ui5-multi-combobox]")
608+
.shadow()
609+
.find<ResponsivePopover>("[ui5-responsive-popover]")
610+
.as("respPopover")
611+
.ui5ResponsivePopoverOpened();
612+
613+
cy.get("@respPopover")
614+
.find("[ui5-toggle-button]")
615+
.should("not.have.attr", "disabled");
616+
});
617+
618+
it("Should show only selected items on n-more click and toggle the button", () => {
619+
cy.mount(
620+
<MultiComboBox placeholder="Select options">
621+
<MultiComboBoxItem text="Item 1" selected />
622+
<MultiComboBoxItem text="Item 2" selected />
623+
<MultiComboBoxItem text="Item 3" />
624+
<MultiComboBoxItem text="Item 4" selected />
625+
</MultiComboBox>
626+
);
627+
628+
cy.get("[ui5-multi-combobox]")
629+
.shadow()
630+
.find("[ui5-tokenizer]")
631+
.shadow()
632+
.find(".ui5-tokenizer-more-text")
633+
.realClick();
634+
635+
cy.get("[ui5-multi-combobox]")
636+
.shadow()
637+
.find<ResponsivePopover>("[ui5-responsive-popover]")
638+
.as("respPopover")
639+
.ui5ResponsivePopoverOpened();
640+
641+
cy.get("@respPopover")
642+
.find("[ui5-toggle-button]")
643+
.should("have.attr", "pressed");
644+
645+
cy.get("@respPopover")
646+
.find("[ui5-list]")
647+
.find("slot")
648+
.should("have.length", 3);
649+
});
650+
651+
it("Shows all items matching 'I' after clicking N-more and typing in the popover input", () => {
652+
cy.mount(
653+
<MultiComboBox placeholder="Select options">
654+
<MultiComboBoxItem text="Item 1" selected />
655+
<MultiComboBoxItem text="Item 2" />
656+
<MultiComboBoxItem text="Item 3" />
657+
<MultiComboBoxItem text="Item 4" selected />
658+
</MultiComboBox>
659+
);
660+
661+
cy.get("[ui5-multi-combobox]")
662+
.shadow()
663+
.find("[ui5-tokenizer]")
664+
.shadow()
665+
.find(".ui5-tokenizer-more-text")
666+
.realClick();
667+
668+
cy.get("[ui5-multi-combobox]")
669+
.shadow()
670+
.find<ResponsivePopover>("[ui5-responsive-popover]")
671+
.as("respPopover")
672+
.ui5ResponsivePopoverOpened();
673+
674+
cy.get("@respPopover")
675+
.find("[ui5-toggle-button]")
676+
.should("have.attr", "pressed");
677+
678+
cy.get("@respPopover")
679+
.find("[ui5-list]")
680+
.find("slot")
681+
.should("have.length", 2);
682+
683+
cy.get("@respPopover")
684+
.find("[ui5-input]")
685+
.realClick()
686+
.realType("I");
687+
688+
cy.get("@respPopover")
689+
.find("[ui5-toggle-button]")
690+
.should("not.have.attr", "pressed");
691+
692+
cy.get("@respPopover")
693+
.find("[ui5-list]")
694+
.find("slot")
695+
.should("have.length", 4);
696+
});
573697
});
574698

575699
describe("Value state header", () => {

packages/main/src/MultiComboBox.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -628,6 +628,10 @@ class MultiComboBox extends UI5Element implements IFormInputElement {
628628
this._dialogInputValueState = this.valueState;
629629
}
630630

631+
if (this.filterSelected) {
632+
this.filterSelected = false;
633+
}
634+
631635
this.value = value;
632636
this._shouldFilterItems = true;
633637
this.valueBeforeAutoComplete = value;
@@ -646,6 +650,7 @@ class MultiComboBox extends UI5Element implements IFormInputElement {
646650
if (!isEnter(e)) {
647651
return;
648652
}
653+
649654
const { value } = (e.target as Input);
650655
const matchingItem = this._getItems().find(item => item.text === value);
651656

packages/main/src/MultiComboBoxPopoverTemplate.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ export default function MultiComboBoxPopoverTemplate(this: MultiComboBox) {
5555
icon={multiSelectAll}
5656
design="Transparent"
5757
pressed={this._showAllItemsButtonPressed}
58+
disabled={this._getSelectedItems().length === 0}
5859
onClick={this.filterSelectedItems}
5960
accessibleName={this._showSelectedButtonAccessibleNameText}
6061
></ToggleButton>

0 commit comments

Comments
 (0)