Skip to content

Commit 88b7013

Browse files
fix(checkbox): align checkbox properly in item using start alignment (#29850)
Issue number: resolves #29837 --------- ## What is the current behavior? The checkbox is not aligned properly to the top when using a long label with `alignment="start"` inside of an `ion-item`: ```html <ion-item> <ion-checkbox justify="start" alignment="start"> <ion-label class="ion-text-wrap"> Enable Notifications Enable Notifications Enable Notifications </ion-label> </ion-checkbox> </ion-item> ``` ## What is the new behavior? - Applies the same margin to the `.native-wrapper` (checkbox) as the label. - Adds a screenshot test to verify the alignment ## Does this introduce a breaking change? - [ ] Yes - [x] No ## Other information | Before | After | | --- | --- | | ![before](https://github.com/user-attachments/assets/53579523-e8b5-4152-ae91-14847cb395e4) | ![after](https://github.com/user-attachments/assets/0d7315ed-3294-4a27-82fe-6900eb9db1c0) | | ![before](https://github.com/user-attachments/assets/ca025a94-4ef7-44b4-85d0-5183e4326814) | ![after](https://github.com/user-attachments/assets/fab60703-1196-48e8-a485-2f33c4893aba) | - [Label Preview](https://ionic-framework-git-rou-11163-ionic1.vercel.app/src/components/checkbox/test/label) - [Item Preview](https://ionic-framework-git-rou-11163-ionic1.vercel.app/src/components/checkbox/test/item) > [!NOTE] > The alignment on the Material Design checkbox is still slightly off. I could add margin directly to its checkbox but then it would change the margin of the checkbox in all use cases.
1 parent f1d50c0 commit 88b7013

16 files changed

+54
-2
lines changed

core/src/components/checkbox/checkbox.scss

+4-1
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,10 @@
8787
overflow: hidden;
8888
}
8989

90-
:host(.in-item) .label-text-wrapper {
90+
// Checkboxes that are not slotted inside an item and are not used with a
91+
// stacked label should have margins equal to those of the label.
92+
:host(.in-item) .label-text-wrapper,
93+
:host(.in-item:not(.checkbox-label-placement-stacked):not([slot])) .native-wrapper {
9194
@include margin($checkbox-item-label-margin-top, null, $checkbox-item-label-margin-bottom, null);
9295
}
9396

core/src/components/checkbox/test/item/checkbox.e2e.ts

+23-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ configs({ directions: ['ltr'] }).forEach(({ title, screenshot, config }) => {
5151
});
5252
});
5353

54-
configs({ directions: ['ltr'], modes: ['md'] }).forEach(({ title, screenshot, config }) => {
54+
configs({ directions: ['ltr'] }).forEach(({ title, screenshot, config }) => {
5555
test.describe(title('checkbox: long label in item'), () => {
5656
test('should render margins correctly when using long label in item', async ({ page }) => {
5757
await page.setContent(
@@ -69,6 +69,28 @@ configs({ directions: ['ltr'], modes: ['md'] }).forEach(({ title, screenshot, co
6969
const list = page.locator('ion-list');
7070
await expect(list).toHaveScreenshot(screenshot(`checkbox-long-label-in-item`));
7171
});
72+
test('should render margins correctly when using long label in item with start alignment', async ({
73+
page,
74+
}, testInfo) => {
75+
testInfo.annotations.push({
76+
type: 'issue',
77+
description: 'https://github.com/ionic-team/ionic-framework/issues/29837',
78+
});
79+
await page.setContent(
80+
`
81+
<ion-list>
82+
<ion-item>
83+
<ion-checkbox justify="start" alignment="start">
84+
<ion-label class="ion-text-wrap">Enable Notifications Enable Notifications Enable Notifications</ion-label>
85+
</ion-checkbox>
86+
</ion-item>
87+
</ion-list>
88+
`,
89+
config
90+
);
91+
const list = page.locator('ion-list');
92+
await expect(list).toHaveScreenshot(screenshot(`checkbox-long-label-in-item-align-start`));
93+
});
7294
});
7395

7496
test.describe(title('checkbox: stacked label in item'), () => {

core/src/components/checkbox/test/item/index.html

+9
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,15 @@ <h1>Multiline Label</h1>
181181
</ion-checkbox>
182182
</ion-item>
183183
</div>
184+
<div class="grid-item">
185+
<ion-item>
186+
<ion-checkbox justify="start" alignment="start">
187+
<ion-label class="ion-text-wrap">
188+
Enable Notifications Enable Notifications Enable Notifications
189+
</ion-label>
190+
</ion-checkbox>
191+
</ion-item>
192+
</div>
184193
</div>
185194
</ion-content>
186195
</ion-app>

core/src/components/checkbox/test/label/index.html

+18
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,24 @@ <h2>Align Center</h2>
113113
<ion-checkbox label-placement="stacked" alignment="center">Enable Notifications</ion-checkbox>
114114
</div>
115115
</div>
116+
117+
<h1>Multiline Label</h1>
118+
<div class="grid">
119+
<div class="grid-item">
120+
<ion-checkbox justify="start">
121+
<ion-label class="ion-text-wrap">
122+
Enable Notifications Enable Notifications Enable Notifications
123+
</ion-label>
124+
</ion-checkbox>
125+
</div>
126+
<div class="grid-item">
127+
<ion-checkbox justify="start" alignment="start">
128+
<ion-label class="ion-text-wrap">
129+
Enable Notifications Enable Notifications Enable Notifications
130+
</ion-label>
131+
</ion-checkbox>
132+
</div>
133+
</div>
116134
</ion-content>
117135
</ion-app>
118136
</body>

0 commit comments

Comments
 (0)