Skip to content

Commit 8fa41a7

Browse files
authored
feat(ui5-popover): allow min-width control via standard CSS styling (#13607)
JIRA: BGSOFUIRODOPI-3608
1 parent f5b49c7 commit 8fa41a7

4 files changed

Lines changed: 103 additions & 5 deletions

File tree

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

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1896,3 +1896,77 @@ describe("Opener visibility in scrollable containers", () => {
18961896
cy.get("[ui5-popover]").should("have.prop", "open", false);
18971897
});
18981898
});
1899+
1900+
describe("Min Width via CSS", () => {
1901+
it("should apply min-width when set via style attribute", () => {
1902+
cy.mount(
1903+
<>
1904+
<Button id="btnMinWidth">Open Popover</Button>
1905+
<Popover id="popMinWidth" opener="btnMinWidth" style={{ minWidth: "300px" }} headerText="Min Width Test">
1906+
<div>Small content</div>
1907+
</Popover>
1908+
</>
1909+
);
1910+
1911+
cy.get("[ui5-popover]").invoke("prop", "open", true);
1912+
1913+
cy.get("[ui5-popover]")
1914+
.should("have.css", "min-width", "300px");
1915+
});
1916+
1917+
it("should allow content wider than minWidth", () => {
1918+
cy.mount(
1919+
<>
1920+
<Button id="btnMinWidthWide">Open Popover</Button>
1921+
<Popover id="popMinWidthWide" opener="btnMinWidthWide" style={{ minWidth: "200px" }}>
1922+
<div style={{ width: "400px", padding: "10px" }}>
1923+
This content is wider than the minWidth setting, and the popover should expand to fit it.
1924+
</div>
1925+
</Popover>
1926+
</>
1927+
);
1928+
1929+
cy.get("[ui5-popover]").invoke("prop", "open", true);
1930+
1931+
cy.get("[ui5-popover]")
1932+
.then($popover => {
1933+
const width = $popover[0].getBoundingClientRect().width;
1934+
// Content is 400px + padding, popover should be wider than minWidth
1935+
expect(width).to.be.greaterThan(200);
1936+
});
1937+
});
1938+
1939+
it("should work with resizable popover", () => {
1940+
cy.mount(
1941+
<>
1942+
<Button id="btnMinWidthResizable">Open Resizable Popover</Button>
1943+
<Popover id="popMinWidthResizable" opener="btnMinWidthResizable" style={{ minWidth: "400px" }} resizable headerText="Resizable with Min Width">
1944+
<div>Content that can be resized but not below 400px</div>
1945+
</Popover>
1946+
</>
1947+
);
1948+
1949+
cy.get("[ui5-popover]").invoke("prop", "open", true);
1950+
1951+
cy.get("[ui5-popover]")
1952+
.should("have.css", "min-width", "400px");
1953+
1954+
cy.get("[ui5-popover]")
1955+
.shadow()
1956+
.find(".ui5-popover-resize-handle")
1957+
.should("be.visible");
1958+
1959+
cy.get("[ui5-popover]")
1960+
.shadow()
1961+
.find(".ui5-popover-resize-handle")
1962+
.trigger("mousedown", { button: 0 })
1963+
.trigger("mousemove", { clientX: -200, clientY: 0 })
1964+
.trigger("mouseup");
1965+
1966+
cy.get("[ui5-popover]")
1967+
.then($popover => {
1968+
const currentWidth = $popover[0].getBoundingClientRect().width;
1969+
expect(currentWidth).to.be.at.least(400);
1970+
});
1971+
});
1972+
});

packages/main/src/PopoverResize.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ class PopoverResize {
240240
minHeight,
241241
} = window.getComputedStyle(this._popover);
242242

243-
const domRefComputedStyle = window.getComputedStyle(this._popover._getRealDomRef!());
243+
const domRefComputedStyle = window.getComputedStyle(this._popover);
244244

245245
this._initialClientX = e.clientX;
246246
this._initialClientY = e.clientY;

packages/main/src/themes/Popover.css

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
:host {
2+
min-width: 6.25rem;
23
box-shadow: var(--_ui5_popover_box_shadow);
34
background-color: var(--_ui5_popover_background);
45
max-width: calc(100vw - (100vw - 100%) - 2 * var(--_ui5_popup_viewport_margin));
@@ -59,10 +60,6 @@
5960
display: none;
6061
}
6162

62-
.ui5-popover-root {
63-
min-width: 6.25rem;
64-
}
65-
6663
.ui5-popover-arrow {
6764
pointer-events: none;
6865
display: block;

packages/main/test/pages/Popover.html

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,25 @@
3232
<iframe id="clickThisIframeInsideShadowRoot" src="./Test.html"></iframe>
3333
</template>
3434
</div>
35+
<ui5-button id="btnTestMinWidth">Open Popover with minWidth: 500px</ui5-button>
36+
<ui5-popover id="popTestMinWidth" opener="btnTestMinWidth" header-text="minWidth: 500px" style="min-width: 500px;">
37+
<div style="padding: 10px;">
38+
This popover has min-width set to 500px.
39+
</div>
40+
</ui5-popover>
41+
42+
<br><br>
43+
44+
<ui5-button id="btnTestMinWidthResizable">Open Resizable Popover with minWidth: 400px</ui5-button>
45+
<ui5-popover id="popTestMinWidthResizable" opener="btnTestMinWidthResizable" resizable header-text="Resizable + minWidth: 400px" style="min-width: 400px;">
46+
<div style="padding: 10px; min-height: 100px;">
47+
This popover is resizable with minWidth: 400px.<br>
48+
Try resizing - it won't go below 400px width!
49+
</div>
50+
</ui5-popover>
51+
52+
<br><br>
53+
3554
<ui5-button id="btn">Click me !</ui5-button>
3655

3756
<ui5-popover id="pop" class="popover6auto" placement="Top" accessible-name="This popover is important">
@@ -676,6 +695,14 @@ <h3>Popover in ShadowRoot, Opener set as ID in window.document</h3>
676695

677696
<script>
678697

698+
btnTestMinWidth.addEventListener("click", function () {
699+
popTestMinWidth.open = true;
700+
});
701+
702+
btnTestMinWidthResizable.addEventListener("click", function () {
703+
popTestMinWidthResizable.open = true;
704+
});
705+
679706
test.addEventListener("click", function (event) {
680707
groupPop.open = true;
681708
});

0 commit comments

Comments
 (0)