Skip to content
Open
69 changes: 69 additions & 0 deletions packages/main/cypress/specs/CheckBox.cy.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,75 @@ describe("CheckBox general interaction", () => {
.find("ui5-icon")
.should("have.attr", "name", "tri-state");
});

it("tests font-size based scaling for standalone checkboxes", () => {
cy.mount(
<div>
<CheckBox style={{ fontSize: "12px" }} checked />
<CheckBox style={{ fontSize: "48px" }} checked />
<CheckBox style={{ fontSize: "48px" }} checked indeterminate />
</div>
);

let smallInnerWidth: number;
let smallInnerHeight: number;
let largeInnerWidth: number;
let largeInnerHeight: number;
let smallIconWidth: number;
let smallIconHeight: number;
let largeIconWidth: number;
let largeIconHeight: number;

// Measure small checkbox (12px)
cy.get("[ui5-checkbox]").eq(0)
.shadow()
.find(".ui5-checkbox-inner")
.then($inner => {
smallInnerWidth = $inner[0].offsetWidth;
smallInnerHeight = $inner[0].offsetHeight;
});

cy.get("[ui5-checkbox]").eq(0)
.shadow()
.find(".ui5-checkbox-icon")
.then($icon => {
smallIconWidth = $icon[0].offsetWidth;
smallIconHeight = $icon[0].offsetHeight;
});

// Measure large checkbox (48px)
cy.get("[ui5-checkbox]").eq(1)
.shadow()
.find(".ui5-checkbox-inner")
.then($inner => {
largeInnerWidth = $inner[0].offsetWidth;
largeInnerHeight = $inner[0].offsetHeight;
});

cy.get("[ui5-checkbox]").eq(1)
.shadow()
.find(".ui5-checkbox-icon")
.then($icon => {
largeIconWidth = $icon[0].offsetWidth;
largeIconHeight = $icon[0].offsetHeight;

// Perform assertions after all measurements are captured
// 48px checkbox should be ~4x larger than 12px checkbox
expect(largeInnerWidth).to.be.closeTo(smallInnerWidth * 4, 2);
expect(largeInnerHeight).to.be.closeTo(smallInnerHeight * 4, 2);
expect(largeIconWidth).to.be.closeTo(smallIconWidth * 4, 2);
expect(largeIconHeight).to.be.closeTo(smallIconHeight * 4, 2);
});

// Verify indeterminate state (tri-state box) scales as well
cy.get("[ui5-checkbox]").eq(2)
.shadow()
.find(".ui5-checkbox-inner")
.then($inner => {
expect($inner[0].offsetWidth).to.be.greaterThan(smallInnerWidth * 3);
expect($inner[0].offsetHeight).to.be.greaterThan(smallInnerHeight * 3);
});
});
});

describe("Accessibility", () => {
Expand Down
51 changes: 47 additions & 4 deletions packages/main/src/themes/CheckBox.css
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,18 @@
display: inline-block;
}

:host(:not([text])) {
font-size: 1.375rem;
padding: var(--_ui5_checkbox_wrapper_padding);
width: fit-content;
height: fit-content;
overflow: visible;
line-height: 0;
--_ui5_checkbox_inner_width_height: 1em;
--_ui5_checkbox_icon_size: 1em;
--_ui5_checkbox_partially_icon_size: .55em;
}

:host([required]) {
vertical-align: middle;
}
Expand Down Expand Up @@ -121,15 +133,23 @@
display: inline-flex;
align-items: center;
max-width: 100%;
min-height: var(--_ui5_checkbox_width_height);
min-width: var(--_ui5_checkbox_width_height);
padding: 0 var(--_ui5_checkbox_wrapper_padding);
box-sizing: border-box;
outline: none;
transition: var(--_ui5_checkbox_transition);
border: var(--_ui5_checkbox_default_focus_border);
border-radius: var(--_ui5_checkbox_border_radius);
box-sizing: border-box;
}

:host(:not([text])) .ui5-checkbox-root {
width: 1em;
height: 1em;
padding: 0;
}

:host([text]) .ui5-checkbox-root {
min-height: var(--_ui5_checkbox_width_height);
min-width: var(--_ui5_checkbox_width_height);
padding: 0 var(--_ui5_checkbox_wrapper_padding);
}

/* focused */
Expand All @@ -144,6 +164,13 @@
border-radius: var(--_ui5_checkbox_focus_border_radius);
}

:host(:not([text])[desktop]) .ui5-checkbox-root:focus::before,
:host(:not([text])) .ui5-checkbox-root:focus-visible::before {
/* Fixed focus outline gap (proportional to text checkbox focus position): -0.425rem / 0.3125rem ≈ -1.36 */
inset-inline: calc(var(--_ui5_checkbox_focus_position) * -1.36);
inset-block: calc(var(--_ui5_checkbox_focus_position) * -1.36);
}

:host([text]) .ui5-checkbox-root {
padding-inline-end: var(--_ui5_checkbox_right_focus_distance);
}
Expand Down Expand Up @@ -250,11 +277,22 @@
transform: translate(-50%, -50%);
}

:host(:not([text])) .ui5-checkbox-icon {
width: 0.75em;
height: 0.75em;
}

/* Display only mode */
:host([display-only]) {
cursor: default;
}

:host([display-only]:not([text])) {
font-size: 1rem;
width: 1em;
height: 1em;
}

:host([display-only]) .ui5-checkbox-display-only-icon-inner [ui5-icon] {
color: var(--sapTextColor);
}
Expand All @@ -268,3 +306,8 @@
align-items: center;
justify-content: center;
}

:host([display-only]:not([text])) .ui5-checkbox-display-only-icon-inner [ui5-icon] {
width: 1em;
height: 1em;
}
32 changes: 32 additions & 0 deletions packages/main/test/pages/CheckBox.html
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,38 @@
<ui5-switch style="width: 100%; border: 1px solid red;"></ui5-switch>
</div>

<br><br>
<ui5-title>Font-size based scaling (standalone checkboxes only)</ui5-title>
<ui5-checkbox style="font-size: 12px;"></ui5-checkbox>
<ui5-checkbox style="font-size: 12px;" checked></ui5-checkbox>
<ui5-checkbox style="font-size: 12px;" checked indeterminate></ui5-checkbox>
<ui5-checkbox style="font-size: 24px;"></ui5-checkbox>
<ui5-checkbox style="font-size: 24px;" checked></ui5-checkbox>
<ui5-checkbox style="font-size: 24px;" checked indeterminate></ui5-checkbox>
<ui5-checkbox style="font-size: 48px;"></ui5-checkbox>
<ui5-checkbox style="font-size: 48px;" checked></ui5-checkbox>
<ui5-checkbox style="font-size: 48px;" checked indeterminate></ui5-checkbox>

<br><br>
<ui5-title>Font-size scaling with display-only</ui5-title>
<ui5-checkbox style="font-size: 12px;" display-only></ui5-checkbox>
<ui5-checkbox style="font-size: 12px;" display-only checked></ui5-checkbox>
<ui5-checkbox style="font-size: 24px;" display-only></ui5-checkbox>
<ui5-checkbox style="font-size: 24px;" display-only checked></ui5-checkbox>
<ui5-checkbox style="font-size: 48px;" display-only></ui5-checkbox>
<ui5-checkbox style="font-size: 48px;" display-only checked></ui5-checkbox>

<br><br>
<ui5-title>Font-size scaling with padding: 0</ui5-title>
<div style="margin-top: 1rem;">
<ui5-checkbox style="font-size: 12px; padding: 0;"></ui5-checkbox>
<ui5-checkbox style="font-size: 12px; padding: 0;" checked></ui5-checkbox>
<ui5-checkbox style="font-size: 24px; padding: 0;"></ui5-checkbox>
<ui5-checkbox style="font-size: 24px; padding: 0;" checked></ui5-checkbox>
<ui5-checkbox style="font-size: 48px; padding: 0;"></ui5-checkbox>
<ui5-checkbox style="font-size: 48px; padding: 0;" checked></ui5-checkbox>
</div>

<script>
var hcb = false;
var cbForm = document.querySelector("#cbForm");
Expand Down
Loading