From 04fa78580a1847ae497c99a2db712ef0e2e0c3f5 Mon Sep 17 00:00:00 2001 From: PetyaMarkovaBogdanova Date: Tue, 22 Jul 2025 12:34:37 +0300 Subject: [PATCH 1/7] chore(ui5-toolbar-select): value and label added --- packages/main/cypress/specs/Toolbar.cy.tsx | 57 +++++++++++++++++++++ packages/main/src/ToolbarSelect.ts | 39 ++++++++++++++ packages/main/src/ToolbarSelectTemplate.tsx | 8 +++ 3 files changed, 104 insertions(+) diff --git a/packages/main/cypress/specs/Toolbar.cy.tsx b/packages/main/cypress/specs/Toolbar.cy.tsx index b1b0fc53af68..6fdc5738bce7 100644 --- a/packages/main/cypress/specs/Toolbar.cy.tsx +++ b/packages/main/cypress/specs/Toolbar.cy.tsx @@ -458,4 +458,61 @@ describe("Toolbar Select", () => { }); }); }); + + it("Should handle toolbar-select with width larger than the toolbar", async () => { + cy.mount( + + + 1 + 2 + 3 + + + ); + cy.viewport(220, 1080); // Set a small viewport width to trigger overflow + + // Add a toolbar-select element with a large width + cy.get("#otb_d").shadow().within(() => { + cy.wait(2000); + // Click the overflow button + cy.get(".ui5-tb-overflow-btn").click(); + }); + + // Verify the toolbar-select is rendered inside the popover + cy.get("ui5-toolbar-select").should("be.visible"); + }); + + it("Should correctly handle the 'value' property and 'label' slot of ToolbarSelect", () => { + // Mount the Toolbar with a ToolbarSelect component + cy.mount( + + + Select an Option: + Option 1 + Option 2 + Option 3 + + + ); + + // Verify the initial value of the ToolbarSelect + cy.get("ui5-select", { includeShadowDom: true }) + .should("have.attr", "value", "Option 2"); + + // Verify the label slot content + cy.get("ui5-select", { includeShadowDom: true }) + .find("span[slot='label']") + .should("contain.text", "Select an Option:"); + + // Change the value of the ToolbarSelect + cy.get("ui5-select", { includeShadowDom: true }) + .click() + .find("ui5-option") + .contains("Option 3") + .click(); + + // Verify the updated value of the ToolbarSelect + cy.get("ui5-select", { includeShadowDom: true }) + .should("have.attr", "value", "Option 3"); + }); }); \ No newline at end of file diff --git a/packages/main/src/ToolbarSelect.ts b/packages/main/src/ToolbarSelect.ts index 79faa0f938eb..8536f3c7ee2d 100644 --- a/packages/main/src/ToolbarSelect.ts +++ b/packages/main/src/ToolbarSelect.ts @@ -90,6 +90,21 @@ class ToolbarSelect extends ToolbarItem { @slot({ "default": true, type: HTMLElement, invalidateOnChildChange: true }) options!: Array; + /** + * Defines the HTML element that will be displayed in the component input part, + * representing the selected option. + * + * **Note:** If not specified and `ui5-option-custom` is used, + * either the option's `display-text` or its textContent will be displayed. + * + * **Note:** If not specified and `ui5-option` is used, + * the option's textContent will be displayed. + * @public + * @since 1.17.0 + */ + @slot() + label!: Array; + /** * Defines the value state of the component. * @default "None" @@ -124,6 +139,26 @@ class ToolbarSelect extends ToolbarItem { @property() accessibleNameRef?: string; + /** + * Defines the value of the component: + * + * - when get - returns the value of the component or the value/text content of the selected option. + * - when set - selects the option with matching `value` property or text content. + * + * **Note:** Use either the Select's value or the Options' selected property. + * Mixed usage could result in unexpected behavior. + * + * **Note:** If the given value does not match any existing option, + * no option will be selected and the Select component will be displayed as empty. + * @public + * @default "" + * @since + * @formProperty + * @formEvents change liveChange + */ + @property() + value?: string; + onClick(e: Event): void { e.stopImmediatePropagation(); const prevented = !this.fireDecoratorEvent("click", { targetRef: e.target as HTMLElement }); @@ -174,6 +209,10 @@ class ToolbarSelect extends ToolbarItem { width: this.width, }; } + + get hasCustomLabel() { + return !!this.label.length; + } } ToolbarSelect.define(); diff --git a/packages/main/src/ToolbarSelectTemplate.tsx b/packages/main/src/ToolbarSelectTemplate.tsx index 0ff8b3fa347a..4bad01396dfa 100644 --- a/packages/main/src/ToolbarSelectTemplate.tsx +++ b/packages/main/src/ToolbarSelectTemplate.tsx @@ -3,10 +3,12 @@ import Select from "./Select.js"; import Option from "./Option.js"; export default function ToolbarSelectTemplate(this: ToolbarSelect) { + const HTMLElementForLabel = this.hasCustomLabel ? this.label[0]?.tagName?.toLowerCase() : "span"; return ( {this.hasCustomLabel && - - {this.label[0].innerHTML} - + () } {this.options.map((option, index) => (