fix(many): do not grow slotted checkboxes, radios, selects and toggles (#29501)
Issue number: resolves #29423
---------
## What is the current behavior?
I fixed a bug where icon was collapsing its width when next to a
checkbox, radio or toggle to match the styles of select in
https://github.com/ionic-team/ionic-framework/pull/29328. This caused a
regression for checkboxes, radios, and toggles when slotted inside of an
item. Our test coverage for this was not great, as the slotted inputs
test in item had so many elements that it was not apparent that this bug
was introduced. In addition, the select itself presented the same issue
before my PR and this is a regression from the v7 behavior. See the
following Codepens to see the regression:
- [Ionic v7](https://codepen.io/brandyscarney/pen/jOoPzoL)
- [Ionic v8](https://codepen.io/brandyscarney/pen/KKLpoLX)
## What is the new behavior?
- Updates the checkbox, radio, select, and toggle to reset the flex
property when slotted.
- Adds test coverage for the previous fix I did in
https://github.com/ionic-team/ionic-framework/pull/29328 where icons
were collapsing their width next to checkboxes, radios and toggles. This
was reproducible with a div and easier to see in a test so I used a div
with a background instead of an icon.
- Adds better test coverage for this fix which separates each component
(checkbox, radio, select, toggle) into their own screenshot test to make
sure the width is shrinking or expanding properly based on where it is
located in an item.
## Does this introduce a breaking change?
- [ ] Yes
- [x] No
## Other information
| Before fix
9b59138011
| After |
| ---| ---|
| 
| 
|
<table width="100%">
<tr align="center">
<td width="50%"><b>Before regression fix</b></td>
<td width="50%"><b>After</b></td>
</tr>
<tr>
<td width="50%"><img alt="before-regression-fix"
src="https://github.com/ionic-team/ionic-framework/assets/6577830/bb1aea84-6c83-4fbe-96ad-855c1c9cca95"></td>
<td width="50%"><img alt="after-regression-fix"
src="https://github.com/ionic-team/ionic-framework/assets/6577830/655dab88-55a9-4961-a7fb-2a3233aa0004"></td>
</tr>
</table>
@ -52,6 +52,11 @@
|
|||||||
*/
|
*/
|
||||||
:host([slot="start"]),
|
:host([slot="start"]),
|
||||||
:host([slot="end"]) {
|
:host([slot="end"]) {
|
||||||
|
// Reset the flex property when the checkbox
|
||||||
|
// is slotted to avoid growing the element larger
|
||||||
|
// than its content.
|
||||||
|
flex: initial;
|
||||||
|
|
||||||
width: auto;
|
width: auto;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -200,3 +200,57 @@ configs({ modes: ['ios'], directions: ['ltr'] }).forEach(({ title, config }) =>
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This behavior does not vary across directions
|
||||||
|
*/
|
||||||
|
configs({ directions: ['ltr'] }).forEach(({ title, screenshot, config }) => {
|
||||||
|
test.describe(title('item: inputs'), () => {
|
||||||
|
test('should not shrink the width of a div next to a checkbox, radio, select or toggle', async ({
|
||||||
|
page,
|
||||||
|
}, testInfo) => {
|
||||||
|
testInfo.annotations.push({
|
||||||
|
type: 'issue',
|
||||||
|
description: 'https://github.com/ionic-team/ionic-framework/issues/29319',
|
||||||
|
});
|
||||||
|
await page.setContent(
|
||||||
|
`
|
||||||
|
<style>
|
||||||
|
.box {
|
||||||
|
background: lightgreen;
|
||||||
|
|
||||||
|
width: 60px;
|
||||||
|
height: 60px;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
|
||||||
|
<ion-list lines="none">
|
||||||
|
<ion-item>
|
||||||
|
<div class="box"></div>
|
||||||
|
<ion-checkbox>Checkbox</ion-checkbox>
|
||||||
|
</ion-item>
|
||||||
|
<ion-item>
|
||||||
|
<div class="box"></div>
|
||||||
|
<ion-radio>Radio</ion-radio>
|
||||||
|
</ion-item>
|
||||||
|
<ion-item>
|
||||||
|
<div class="box"></div>
|
||||||
|
<ion-select label="Select">
|
||||||
|
<ion-select-option>Option</ion-select-option>
|
||||||
|
</ion-select>
|
||||||
|
</ion-item>
|
||||||
|
<ion-item>
|
||||||
|
<div class="box"></div>
|
||||||
|
<ion-toggle>Toggle</ion-toggle>
|
||||||
|
</ion-item>
|
||||||
|
</ion-list>
|
||||||
|
`,
|
||||||
|
config
|
||||||
|
);
|
||||||
|
|
||||||
|
const list = page.locator('ion-list');
|
||||||
|
|
||||||
|
await expect(list).toHaveScreenshot(screenshot(`item-inputs-div-with-inputs`));
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|||||||
|
After Width: | Height: | Size: 8.4 KiB |
|
After Width: | Height: | Size: 9.6 KiB |
|
After Width: | Height: | Size: 7.6 KiB |
|
After Width: | Height: | Size: 7.9 KiB |
|
After Width: | Height: | Size: 9.3 KiB |
|
After Width: | Height: | Size: 6.9 KiB |
@ -12,3 +12,163 @@ configs().forEach(({ title, screenshot, config }) => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This behavior does not vary across directions
|
||||||
|
*/
|
||||||
|
configs({ directions: ['ltr'] }).forEach(({ title, screenshot, config }) => {
|
||||||
|
test.describe(title('item: slotted inputs'), () => {
|
||||||
|
test.describe('checkbox', () => {
|
||||||
|
test('should not expand the slotted checkbox width larger than its content', async ({ page }, testInfo) => {
|
||||||
|
testInfo.annotations.push({
|
||||||
|
type: 'issue',
|
||||||
|
description: 'https://github.com/ionic-team/ionic-framework/issues/29423',
|
||||||
|
});
|
||||||
|
|
||||||
|
await page.setContent(
|
||||||
|
`
|
||||||
|
<ion-list>
|
||||||
|
<ion-item>
|
||||||
|
<ion-checkbox slot="start"></ion-checkbox>
|
||||||
|
<ion-label>Label</ion-label>
|
||||||
|
</ion-item>
|
||||||
|
<ion-item>
|
||||||
|
<ion-label>Label</ion-label>
|
||||||
|
<ion-checkbox slot="end"></ion-checkbox>
|
||||||
|
</ion-item>
|
||||||
|
<ion-item>
|
||||||
|
<ion-checkbox slot="start">Start</ion-checkbox>
|
||||||
|
<ion-label>Label</ion-label>
|
||||||
|
</ion-item>
|
||||||
|
<ion-item>
|
||||||
|
<ion-label>Label</ion-label>
|
||||||
|
<ion-checkbox slot="end">End</ion-checkbox>
|
||||||
|
</ion-item>
|
||||||
|
</ion-list>
|
||||||
|
`,
|
||||||
|
config
|
||||||
|
);
|
||||||
|
|
||||||
|
const list = page.locator('ion-list');
|
||||||
|
|
||||||
|
await expect(list).toHaveScreenshot(screenshot(`item-slotted-inputs-checkbox`));
|
||||||
|
});
|
||||||
|
});
|
||||||
|
test.describe('radio', () => {
|
||||||
|
test('should not expand the slotted radio width larger than its content', async ({ page }, testInfo) => {
|
||||||
|
testInfo.annotations.push({
|
||||||
|
type: 'issue',
|
||||||
|
description: 'https://github.com/ionic-team/ionic-framework/issues/29423',
|
||||||
|
});
|
||||||
|
|
||||||
|
await page.setContent(
|
||||||
|
`
|
||||||
|
<ion-list>
|
||||||
|
<ion-item>
|
||||||
|
<ion-radio slot="start"></ion-radio>
|
||||||
|
<ion-label>Label</ion-label>
|
||||||
|
</ion-item>
|
||||||
|
<ion-item>
|
||||||
|
<ion-label>Label</ion-label>
|
||||||
|
<ion-radio slot="end"></ion-radio>
|
||||||
|
</ion-item>
|
||||||
|
<ion-item>
|
||||||
|
<ion-radio slot="start">Start</ion-radio>
|
||||||
|
<ion-label>Label</ion-label>
|
||||||
|
</ion-item>
|
||||||
|
<ion-item>
|
||||||
|
<ion-label>Label</ion-label>
|
||||||
|
<ion-radio slot="end">End</ion-radio>
|
||||||
|
</ion-item>
|
||||||
|
</ion-list>
|
||||||
|
`,
|
||||||
|
config
|
||||||
|
);
|
||||||
|
|
||||||
|
const list = page.locator('ion-list');
|
||||||
|
|
||||||
|
await expect(list).toHaveScreenshot(screenshot(`item-slotted-inputs-radio`));
|
||||||
|
});
|
||||||
|
});
|
||||||
|
test.describe('select', () => {
|
||||||
|
test('should not expand the slotted select width larger than its content', async ({ page }, testInfo) => {
|
||||||
|
testInfo.annotations.push({
|
||||||
|
type: 'issue',
|
||||||
|
description: 'https://github.com/ionic-team/ionic-framework/issues/29423',
|
||||||
|
});
|
||||||
|
|
||||||
|
await page.setContent(
|
||||||
|
`
|
||||||
|
<ion-list>
|
||||||
|
<ion-item>
|
||||||
|
<ion-select slot="start">
|
||||||
|
<ion-select-option>Option</ion-select-option>
|
||||||
|
</ion-select>
|
||||||
|
<ion-label>Label</ion-label>
|
||||||
|
</ion-item>
|
||||||
|
<ion-item>
|
||||||
|
<ion-label>Label</ion-label>
|
||||||
|
<ion-select slot="end">
|
||||||
|
<ion-select-option>Option</ion-select-option>
|
||||||
|
</ion-select>
|
||||||
|
</ion-item>
|
||||||
|
<ion-item>
|
||||||
|
<ion-select slot="start" label="Start">
|
||||||
|
<ion-select-option>Option</ion-select-option>
|
||||||
|
</ion-select>
|
||||||
|
<ion-label>Label</ion-label>
|
||||||
|
</ion-item>
|
||||||
|
<ion-item>
|
||||||
|
<ion-label>Label</ion-label>
|
||||||
|
<ion-select slot="end" label="End">
|
||||||
|
<ion-select-option>Option</ion-select-option>
|
||||||
|
</ion-select>
|
||||||
|
</ion-item>
|
||||||
|
</ion-list>
|
||||||
|
`,
|
||||||
|
config
|
||||||
|
);
|
||||||
|
|
||||||
|
const list = page.locator('ion-list');
|
||||||
|
|
||||||
|
await expect(list).toHaveScreenshot(screenshot(`item-slotted-inputs-select`));
|
||||||
|
});
|
||||||
|
});
|
||||||
|
test.describe('toggle', () => {
|
||||||
|
test('should not expand the slotted toggle width larger than its content', async ({ page }, testInfo) => {
|
||||||
|
testInfo.annotations.push({
|
||||||
|
type: 'issue',
|
||||||
|
description: 'https://github.com/ionic-team/ionic-framework/issues/29423',
|
||||||
|
});
|
||||||
|
|
||||||
|
await page.setContent(
|
||||||
|
`
|
||||||
|
<ion-list>
|
||||||
|
<ion-item>
|
||||||
|
<ion-toggle slot="start"></ion-toggle>
|
||||||
|
<ion-label>Label</ion-label>
|
||||||
|
</ion-item>
|
||||||
|
<ion-item>
|
||||||
|
<ion-label>Label</ion-label>
|
||||||
|
<ion-toggle slot="end"></ion-toggle>
|
||||||
|
</ion-item>
|
||||||
|
<ion-item>
|
||||||
|
<ion-toggle slot="start">Start</ion-toggle>
|
||||||
|
<ion-label>Label</ion-label>
|
||||||
|
</ion-item>
|
||||||
|
<ion-item>
|
||||||
|
<ion-label>Label</ion-label>
|
||||||
|
<ion-toggle slot="end">End</ion-toggle>
|
||||||
|
</ion-item>
|
||||||
|
</ion-list>
|
||||||
|
`,
|
||||||
|
config
|
||||||
|
);
|
||||||
|
|
||||||
|
const list = page.locator('ion-list');
|
||||||
|
|
||||||
|
await expect(list).toHaveScreenshot(screenshot(`item-slotted-inputs-toggle`));
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|||||||
|
After Width: | Height: | Size: 7.8 KiB |
|
After Width: | Height: | Size: 8.0 KiB |
|
After Width: | Height: | Size: 7.0 KiB |
|
After Width: | Height: | Size: 5.8 KiB |
|
After Width: | Height: | Size: 6.9 KiB |
|
After Width: | Height: | Size: 5.1 KiB |
|
Before Width: | Height: | Size: 23 KiB After Width: | Height: | Size: 23 KiB |
|
Before Width: | Height: | Size: 28 KiB After Width: | Height: | Size: 28 KiB |
|
Before Width: | Height: | Size: 22 KiB After Width: | Height: | Size: 22 KiB |
|
Before Width: | Height: | Size: 23 KiB After Width: | Height: | Size: 23 KiB |
|
Before Width: | Height: | Size: 28 KiB After Width: | Height: | Size: 28 KiB |
|
Before Width: | Height: | Size: 22 KiB After Width: | Height: | Size: 22 KiB |
|
Before Width: | Height: | Size: 21 KiB After Width: | Height: | Size: 21 KiB |
|
Before Width: | Height: | Size: 25 KiB After Width: | Height: | Size: 24 KiB |
|
Before Width: | Height: | Size: 20 KiB After Width: | Height: | Size: 20 KiB |
|
Before Width: | Height: | Size: 21 KiB After Width: | Height: | Size: 21 KiB |
|
Before Width: | Height: | Size: 25 KiB After Width: | Height: | Size: 25 KiB |
|
Before Width: | Height: | Size: 20 KiB After Width: | Height: | Size: 20 KiB |
|
After Width: | Height: | Size: 5.3 KiB |
|
After Width: | Height: | Size: 6.7 KiB |
|
After Width: | Height: | Size: 4.8 KiB |
|
After Width: | Height: | Size: 7.6 KiB |
|
After Width: | Height: | Size: 7.9 KiB |
|
After Width: | Height: | Size: 6.9 KiB |
|
After Width: | Height: | Size: 6.8 KiB |
|
After Width: | Height: | Size: 7.7 KiB |
|
After Width: | Height: | Size: 5.9 KiB |
|
After Width: | Height: | Size: 5.9 KiB |
|
After Width: | Height: | Size: 6.9 KiB |
|
After Width: | Height: | Size: 5.0 KiB |
|
After Width: | Height: | Size: 9.3 KiB |
|
After Width: | Height: | Size: 10 KiB |
|
After Width: | Height: | Size: 8.5 KiB |
|
After Width: | Height: | Size: 8.5 KiB |
|
After Width: | Height: | Size: 9.9 KiB |
|
After Width: | Height: | Size: 7.6 KiB |
@ -72,6 +72,11 @@ input {
|
|||||||
*/
|
*/
|
||||||
:host([slot="start"]),
|
:host([slot="start"]),
|
||||||
:host([slot="end"]) {
|
:host([slot="end"]) {
|
||||||
|
// Reset the flex property when the checkbox
|
||||||
|
// is slotted to avoid growing the element larger
|
||||||
|
// than its content.
|
||||||
|
flex: initial;
|
||||||
|
|
||||||
width: auto;
|
width: auto;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -100,6 +100,11 @@
|
|||||||
*/
|
*/
|
||||||
:host([slot="start"]),
|
:host([slot="start"]),
|
||||||
:host([slot="end"]) {
|
:host([slot="end"]) {
|
||||||
|
// Reset the flex property when the checkbox
|
||||||
|
// is slotted to avoid growing the element larger
|
||||||
|
// than its content.
|
||||||
|
flex: initial;
|
||||||
|
|
||||||
width: auto;
|
width: auto;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -53,6 +53,11 @@
|
|||||||
*/
|
*/
|
||||||
:host([slot="start"]),
|
:host([slot="start"]),
|
||||||
:host([slot="end"]) {
|
:host([slot="end"]) {
|
||||||
|
// Reset the flex property when the checkbox
|
||||||
|
// is slotted to avoid growing the element larger
|
||||||
|
// than its content.
|
||||||
|
flex: initial;
|
||||||
|
|
||||||
width: auto;
|
width: auto;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||