Skip to content

Commit

Permalink
feat(checkbox): display as block when justify or alignment properties…
Browse files Browse the repository at this point in the history
… are defined (#29783)

- Change the checkbox's `display` property to `block` when the `justify` or `alignment` property is set.
- Set the default `justify-content` style to `space-between` so that a checkbox with `width: 100%` set without `justify` or `alignment` set will still have the same default
- Modifies the `label` e2e test to remove the explicit width as setting the property will make them full-width
- Adds two examples to the `label` e2e test of labels that do not have `justify` set but use `width: 100%` to ensure they are working as expected without it
  • Loading branch information
brandyscarney authored Aug 28, 2024
1 parent d737ec1 commit 4ccd15e
Show file tree
Hide file tree
Showing 194 changed files with 97 additions and 47 deletions.
4 changes: 2 additions & 2 deletions core/api.txt
Original file line number Diff line number Diff line change
Expand Up @@ -393,12 +393,12 @@ ion-card-title,css-prop,--color,ios
ion-card-title,css-prop,--color,md

ion-checkbox,shadow
ion-checkbox,prop,alignment,"center" | "start",'center',false,false
ion-checkbox,prop,alignment,"center" | "start" | undefined,undefined,false,false
ion-checkbox,prop,checked,boolean,false,false,false
ion-checkbox,prop,color,"danger" | "dark" | "light" | "medium" | "primary" | "secondary" | "success" | "tertiary" | "warning" | string & Record<never, never> | undefined,undefined,false,true
ion-checkbox,prop,disabled,boolean,false,false,false
ion-checkbox,prop,indeterminate,boolean,false,false,false
ion-checkbox,prop,justify,"end" | "space-between" | "start",'space-between',false,false
ion-checkbox,prop,justify,"end" | "space-between" | "start" | undefined,undefined,false,false
ion-checkbox,prop,labelPlacement,"end" | "fixed" | "stacked" | "start",'start',false,false
ion-checkbox,prop,mode,"ios" | "md",undefined,false,false
ion-checkbox,prop,name,string,this.inputId,false,false
Expand Down
12 changes: 6 additions & 6 deletions core/src/components.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -601,9 +601,9 @@ export namespace Components {
}
interface IonCheckbox {
/**
* How to control the alignment of the checkbox and label on the cross axis. `"start"`: The label and control will appear on the left of the cross axis in LTR, and on the right side in RTL. `"center"`: The label and control will appear at the center of the cross axis in both LTR and RTL.
* How to control the alignment of the checkbox and label on the cross axis. `"start"`: The label and control will appear on the left of the cross axis in LTR, and on the right side in RTL. `"center"`: The label and control will appear at the center of the cross axis in both LTR and RTL. Setting this property will change the checkbox `display` to `block`.
*/
"alignment": 'start' | 'center';
"alignment"?: 'start' | 'center';
/**
* If `true`, the checkbox is selected.
*/
Expand All @@ -621,9 +621,9 @@ export namespace Components {
*/
"indeterminate": boolean;
/**
* How to pack the label and checkbox within a line. `"start"`: The label and checkbox will appear on the left in LTR and on the right in RTL. `"end"`: The label and checkbox will appear on the right in LTR and on the left in RTL. `"space-between"`: The label and checkbox will appear on opposite ends of the line with space between the two elements.
* How to pack the label and checkbox within a line. `"start"`: The label and checkbox will appear on the left in LTR and on the right in RTL. `"end"`: The label and checkbox will appear on the right in LTR and on the left in RTL. `"space-between"`: The label and checkbox will appear on opposite ends of the line with space between the two elements. Setting this property will change the checkbox `display` to `block`.
*/
"justify": 'start' | 'end' | 'space-between';
"justify"?: 'start' | 'end' | 'space-between';
/**
* Where to place the label relative to the checkbox. `"start"`: The label will appear to the left of the checkbox in LTR and to the right in RTL. `"end"`: The label will appear to the right of the checkbox in LTR and to the left in RTL. `"fixed"`: The label has the same behavior as `"start"` except it also has a fixed width. Long text will be truncated with ellipses ("..."). `"stacked"`: The label will appear above the checkbox regardless of the direction. The alignment of the label can be controlled with the `alignment` property.
*/
Expand Down Expand Up @@ -5321,7 +5321,7 @@ declare namespace LocalJSX {
}
interface IonCheckbox {
/**
* How to control the alignment of the checkbox and label on the cross axis. `"start"`: The label and control will appear on the left of the cross axis in LTR, and on the right side in RTL. `"center"`: The label and control will appear at the center of the cross axis in both LTR and RTL.
* How to control the alignment of the checkbox and label on the cross axis. `"start"`: The label and control will appear on the left of the cross axis in LTR, and on the right side in RTL. `"center"`: The label and control will appear at the center of the cross axis in both LTR and RTL. Setting this property will change the checkbox `display` to `block`.
*/
"alignment"?: 'start' | 'center';
/**
Expand All @@ -5341,7 +5341,7 @@ declare namespace LocalJSX {
*/
"indeterminate"?: boolean;
/**
* How to pack the label and checkbox within a line. `"start"`: The label and checkbox will appear on the left in LTR and on the right in RTL. `"end"`: The label and checkbox will appear on the right in LTR and on the left in RTL. `"space-between"`: The label and checkbox will appear on opposite ends of the line with space between the two elements.
* How to pack the label and checkbox within a line. `"start"`: The label and checkbox will appear on the left in LTR and on the right in RTL. `"end"`: The label and checkbox will appear on the right in LTR and on the left in RTL. `"space-between"`: The label and checkbox will appear on opposite ends of the line with space between the two elements. Setting this property will change the checkbox `display` to `block`.
*/
"justify"?: 'start' | 'end' | 'space-between';
/**
Expand Down
15 changes: 15 additions & 0 deletions core/src/components/checkbox/checkbox.scss
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@
flex-grow: 1;

align-items: center;
justify-content: space-between;

height: inherit;

Expand Down Expand Up @@ -170,6 +171,20 @@ input {
align-items: center;
}

// Justify Content & Align Items
// ---------------------------------------------

// The checkbox should be displayed as block when either justify
// or alignment is set; otherwise, these properties will have no
// visible effect.
:host(.checkbox-justify-space-between),
:host(.checkbox-justify-start),
:host(.checkbox-justify-end),
:host(.checkbox-alignment-start),
:host(.checkbox-alignment-center) {
display: block;
}

// Label Placement - Start
// ----------------------------------------------------------------

Expand Down
10 changes: 6 additions & 4 deletions core/src/components/checkbox/checkbox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -86,15 +86,17 @@ export class Checkbox implements ComponentInterface {
* on the left in RTL.
* `"space-between"`: The label and checkbox will appear on opposite
* ends of the line with space between the two elements.
* Setting this property will change the checkbox `display` to `block`.
*/
@Prop() justify: 'start' | 'end' | 'space-between' = 'space-between';
@Prop() justify?: 'start' | 'end' | 'space-between';

/**
* How to control the alignment of the checkbox and label on the cross axis.
* `"start"`: The label and control will appear on the left of the cross axis in LTR, and on the right side in RTL.
* `"center"`: The label and control will appear at the center of the cross axis in both LTR and RTL.
* Setting this property will change the checkbox `display` to `block`.
*/
@Prop() alignment: 'start' | 'center' = 'center';
@Prop() alignment?: 'start' | 'center';

/**
* Emitted when the checked property has changed as a result of a user action such as a click.
Expand Down Expand Up @@ -194,8 +196,8 @@ export class Checkbox implements ComponentInterface {
'checkbox-disabled': disabled,
'checkbox-indeterminate': indeterminate,
interactive: true,
[`checkbox-justify-${justify}`]: true,
[`checkbox-alignment-${alignment}`]: true,
[`checkbox-justify-${justify}`]: justify !== undefined,
[`checkbox-alignment-${alignment}`]: alignment !== undefined,
[`checkbox-label-placement-${labelPlacement}`]: true,
})}
onClick={this.onClick}
Expand Down
2 changes: 1 addition & 1 deletion core/src/components/checkbox/test/a11y/checkbox.e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ configs({ directions: ['ltr'] }).forEach(({ title, config, screenshot }) => {
font-size: 310%;
}
</style>
<ion-checkbox justify="start" checked>Checked</ion-checkbox>
<ion-checkbox checked>Checked</ion-checkbox>
`,
config
);
Expand Down
27 changes: 17 additions & 10 deletions core/src/components/checkbox/test/basic/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,17 @@
</head>
<style>
ion-checkbox {
display: block;
margin-bottom: 8px;
}

ion-checkbox.checkbox-part::part(mark) {
transform: scale(0.5);
transform-origin: center;
}

hr {
background: #ddd;
}
</style>
<body>
<ion-app>
Expand All @@ -33,15 +36,19 @@
</ion-header>

<ion-content class="ion-padding">
<div id="checkboxes">
<ion-checkbox justify="start">Unchecked</ion-checkbox>
<ion-checkbox justify="start" checked>Checked</ion-checkbox>
<ion-checkbox justify="start" disabled>Disabled</ion-checkbox>
<ion-checkbox justify="start" disabled checked>Disabled, Checked</ion-checkbox>
<ion-checkbox justify="start" checked style="--checkmark-width: 7">Checkmark Width</ion-checkbox>
<ion-checkbox justify="start" checked class="checkbox-part">Checkmark Shadow Part</ion-checkbox>
<ion-checkbox justify="start" checked style="--size: 100px">--size</ion-checkbox>
</div>
<ion-checkbox>Unchecked</ion-checkbox><br />
<ion-checkbox checked>Checked</ion-checkbox><br />
<ion-checkbox disabled>Disabled</ion-checkbox><br />
<ion-checkbox disabled checked>Disabled, Checked</ion-checkbox><br />
<ion-checkbox checked style="--checkmark-width: 7">Checkmark Width</ion-checkbox><br />
<ion-checkbox checked class="checkbox-part">Checkmark Shadow Part</ion-checkbox><br />
<ion-checkbox checked style="--size: 100px">--size</ion-checkbox><br />

<hr />

<ion-checkbox checked>Default width</ion-checkbox><br />
<ion-checkbox checked style="width: 200px">Specified width</ion-checkbox><br />
<ion-checkbox checked style="width: 100%">Full-width</ion-checkbox><br />
</ion-content>
</ion-app>
</body>
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
70 changes: 50 additions & 20 deletions core/src/components/checkbox/test/label/checkbox.e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,50 @@ import { expect } from '@playwright/test';
import { configs, test } from '@utils/test/playwright';

/**
* By default ion-checkbox only takes up
* as much space as it needs. Justification is
* used for when the checkbox takes up the full
* line (such as in an ion-item). As a result,
* we set the width of the checkbox so we can
* see the justification results.
* By default ion-checkbox only takes up as much space
* as it needs. Justification is used for when the
* checkbox should take up the full line (such as in an
* ion-item or when it has 100% width).
*/
configs().forEach(({ title, screenshot, config }) => {
test.describe(title('checkbox: label'), () => {
test.describe('checkbox: default placement', () => {
test('should render a space between justification with a full width checkbox', async ({ page }) => {
await page.setContent(
`
<ion-checkbox style="width: 100%">
Label
</ion-checkbox>
`,
config
);

const checkbox = page.locator('ion-checkbox');
await expect(checkbox).toHaveScreenshot(screenshot(`checkbox-label-full-width`));
});

test('should truncate long labels with ellipses', async ({ page }) => {
// Checkbox needs to be full width to truncate properly
// because it is not inside of an `ion-app` in tests
await page.setContent(
`
<ion-checkbox style="width: 100%">
Long Label Long Label Long Label Long Label Long Label Long Label
</ion-checkbox>
`,
config
);

const checkbox = page.locator('ion-checkbox');
await expect(checkbox).toHaveScreenshot(screenshot(`checkbox-label-long-label`));
});
});

test.describe('checkbox: start placement', () => {
test('should render a start justification with label in the start position', async ({ page }) => {
await page.setContent(
`
<ion-checkbox label-placement="start" justify="start" style="width: 200px">Label</ion-checkbox>
<ion-checkbox label-placement="start" justify="start">Label</ion-checkbox>
`,
config
);
Expand All @@ -27,7 +57,7 @@ configs().forEach(({ title, screenshot, config }) => {
test('should render an end justification with label in the start position', async ({ page }) => {
await page.setContent(
`
<ion-checkbox label-placement="start" justify="end" style="width: 200px">Label</ion-checkbox>
<ion-checkbox label-placement="start" justify="end">Label</ion-checkbox>
`,
config
);
Expand All @@ -39,7 +69,7 @@ configs().forEach(({ title, screenshot, config }) => {
test('should render a space between justification with label in the start position', async ({ page }) => {
await page.setContent(
`
<ion-checkbox label-placement="start" justify="space-between" style="width: 200px">Label</ion-checkbox>
<ion-checkbox label-placement="start" justify="space-between">Label</ion-checkbox>
`,
config
);
Expand All @@ -51,23 +81,23 @@ configs().forEach(({ title, screenshot, config }) => {
test('should truncate long labels with ellipses', async ({ page }) => {
await page.setContent(
`
<ion-checkbox label-placement="start" justify="start" style="width: 200px">
<ion-checkbox label-placement="start" justify="start">
Long Label Long Label Long Label Long Label Long Label Long Label
</ion-checkbox>
`,
config
);

const checkbox = page.locator('ion-checkbox');
await expect(checkbox).toHaveScreenshot(screenshot(`checkbox-long-label`));
await expect(checkbox).toHaveScreenshot(screenshot(`checkbox-label-start-justify-start-long-label`));
});
});

test.describe('checkbox: end placement', () => {
test('should render a start justification with label in the end position', async ({ page }) => {
await page.setContent(
`
<ion-checkbox label-placement="end" justify="start" style="width: 200px">Label</ion-checkbox>
<ion-checkbox label-placement="end" justify="start">Label</ion-checkbox>
`,
config
);
Expand All @@ -79,7 +109,7 @@ configs().forEach(({ title, screenshot, config }) => {
test('should render an end justification with label in the end position', async ({ page }) => {
await page.setContent(
`
<ion-checkbox label-placement="end" justify="end" style="width: 200px">Label</ion-checkbox>
<ion-checkbox label-placement="end" justify="end">Label</ion-checkbox>
`,
config
);
Expand All @@ -91,7 +121,7 @@ configs().forEach(({ title, screenshot, config }) => {
test('should render a space between justification with label in the end position', async ({ page }) => {
await page.setContent(
`
<ion-checkbox label-placement="end" justify="space-between" style="width: 200px">Label</ion-checkbox>
<ion-checkbox label-placement="end" justify="space-between">Label</ion-checkbox>
`,
config
);
Expand All @@ -105,7 +135,7 @@ configs().forEach(({ title, screenshot, config }) => {
test('should render a start justification with label in the fixed position', async ({ page }) => {
await page.setContent(
`
<ion-checkbox label-placement="fixed" justify="start" style="width: 200px">This is a long label</ion-checkbox>
<ion-checkbox label-placement="fixed" justify="start">This is a long label</ion-checkbox>
`,
config
);
Expand All @@ -117,7 +147,7 @@ configs().forEach(({ title, screenshot, config }) => {
test('should render an end justification with label in the fixed position', async ({ page }) => {
await page.setContent(
`
<ion-checkbox label-placement="fixed" justify="end" style="width: 200px">This is a long label</ion-checkbox>
<ion-checkbox label-placement="fixed" justify="end">This is a long label</ion-checkbox>
`,
config
);
Expand All @@ -129,7 +159,7 @@ configs().forEach(({ title, screenshot, config }) => {
test('should render a space between justification with label in the fixed position', async ({ page }) => {
await page.setContent(
`
<ion-checkbox label-placement="fixed" justify="space-between" style="width: 200px">This is a long label</ion-checkbox>
<ion-checkbox label-placement="fixed" justify="space-between">This is a long label</ion-checkbox>
`,
config
);
Expand All @@ -143,7 +173,7 @@ configs().forEach(({ title, screenshot, config }) => {
test('should align the label to the start of the container in the stacked position', async ({ page }) => {
await page.setContent(
`
<ion-checkbox label-placement="stacked" alignment="start" style="width: 200px">This is a long label</ion-checkbox>
<ion-checkbox label-placement="stacked" alignment="start">This is a long label</ion-checkbox>
`,
config
);
Expand All @@ -155,7 +185,7 @@ configs().forEach(({ title, screenshot, config }) => {
test('should align the label to the center of the container in the stacked position', async ({ page }) => {
await page.setContent(
`
<ion-checkbox label-placement="stacked" alignment="center" style="width: 200px">This is a long label</ion-checkbox>
<ion-checkbox label-placement="stacked" alignment="center">This is a long label</ion-checkbox>
`,
config
);
Expand All @@ -172,7 +202,7 @@ configs({ modes: ['md'], directions: ['ltr'] }).forEach(({ title, config, screen
test('long label should truncate', async ({ page }) => {
await page.setContent(
`
<ion-checkbox label-placement="stacked" alignment="start" style="width: 200px">Enable Notifications Enable Notifications Enable Notifications Enable Notifications Enable Notifications Enable Notifications Enable Notifications</ion-checkbox>
<ion-checkbox label-placement="stacked" alignment="start">Enable Notifications Enable Notifications Enable Notifications Enable Notifications Enable Notifications Enable Notifications Enable Notifications</ion-checkbox>
`,
config
);
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
4 changes: 0 additions & 4 deletions core/src/components/checkbox/test/label/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,6 @@
padding: 0;
}
}

ion-checkbox {
width: 100%;
}
</style>
</head>

Expand Down

0 comments on commit 4ccd15e

Please sign in to comment.