Skip to content

Commit 6c716bc

Browse files
Petya MarkovaPetyaMarkovaBogdanova
andauthored
fix(ui5-toolbar): disable click events on disabled buttons (#11847)
Co-authored-by: PetyaMarkovaBogdanova <[email protected]>
1 parent 0c7025f commit 6c716bc

File tree

3 files changed

+34
-2
lines changed

3 files changed

+34
-2
lines changed

packages/main/cypress/specs/Toolbar.cy.tsx

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -458,4 +458,34 @@ describe("Toolbar Select", () => {
458458
});
459459
});
460460
});
461-
});
461+
});
462+
463+
describe("Toolbar Button", () => {
464+
it("Should not trigger click event on disabled button", () => {
465+
// Use cy.mount to create the toolbar with buttons and input field
466+
cy.mount(
467+
<div>
468+
<Toolbar id="test-toolbar">
469+
<ToolbarButton disabled>Disabled Button</ToolbarButton>
470+
<ToolbarButton
471+
onClick={() => {
472+
const input = document.getElementById("value-input") as HTMLInputElement;
473+
input.value = (parseInt(input.value, 10) + 1).toString();
474+
}}
475+
>
476+
Enabled Button
477+
</ToolbarButton>
478+
<input id="value-input" type="number" defaultValue="0" />
479+
</Toolbar>
480+
</div>
481+
);
482+
483+
// Test clicking the disabled button
484+
cy.get("ui5-toolbar-button[disabled]").realClick();
485+
cy.get("#value-input").should("have.value", "0");
486+
487+
// Test clicking the non-disabled button
488+
cy.get("ui5-toolbar-button:not([disabled])").realClick();
489+
cy.get("#value-input").should("have.value", "1");
490+
});
491+
});

packages/main/src/ToolbarButton.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import type ButtonDesign from "./types/ButtonDesign.js";
77

88
import ToolbarItem from "./ToolbarItem.js";
99
import ToolbarButtonTemplate from "./ToolbarButtonTemplate.js";
10-
1110
import ToolbarButtonCss from "./generated/themes/ToolbarButton.css.js";
1211

1312
type ToolbarButtonAccessibilityAttributes = ButtonAccessibilityAttributes;

packages/main/src/themes/ToolbarButton.css

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
:host([disabled]:active) {
2+
pointer-events: none;
3+
}
14
.ui5-tb-popover-item.ui5-tb-button::part(button) {
25
justify-content: start;
36
}

0 commit comments

Comments
 (0)