Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(checkbox): display as block when justify or alignment properties are defined #29783

Merged
merged 22 commits into from
Aug 28, 2024
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
720ef8a
feat(checkbox): display as flex when justify property is defined
brandyscarney Aug 20, 2024
9887cf8
style: explicit class names
brandyscarney Aug 20, 2024
7365fb3
fix(checkbox): use flex display and apply width 100% to checkbox wrapper
brandyscarney Aug 21, 2024
55a4843
Revert "fix(checkbox): use flex display and apply width 100% to check…
brandyscarney Aug 22, 2024
dcb8a4a
fix(checkbox): only apply justify property in item
brandyscarney Aug 22, 2024
a669fc2
fix(checkbox): set justify content in the css instead
brandyscarney Aug 22, 2024
86bf565
fix(checkbox): 100% width wrapper for long labels
brandyscarney Aug 22, 2024
4097c38
chore(): add updated snapshots
Ionitron Aug 22, 2024
75aa917
test(checkbox): remove justify property from a11y test
brandyscarney Aug 22, 2024
dd7f779
test(checkbox): remove explicit width from label tests
brandyscarney Aug 22, 2024
50b49a3
chore(): add updated snapshots
brandyscarney Aug 22, 2024
3742d54
test(checkbox): add tests for truncating and full width checkbox
brandyscarney Aug 23, 2024
c620298
chore(): add updated snapshots
brandyscarney Aug 23, 2024
4bce2f3
test(checkbox): add full-width example, remove display block
brandyscarney Aug 23, 2024
bcba3d5
fix(checkbox): display flex when align is set
brandyscarney Aug 23, 2024
cf38d15
chore(): add updated snapshots
brandyscarney Aug 23, 2024
fc3f1db
fix(checkbox): change display to block & document it
brandyscarney Aug 23, 2024
d284b02
fix(checkbox): remove width 100%
brandyscarney Aug 23, 2024
6c9738e
chore(): add updated snapshots
brandyscarney Aug 23, 2024
6647ed2
style: lint
brandyscarney Aug 23, 2024
a8120f3
Merge branch 'feature-8.3' into ROU-10906
brandyscarney Aug 26, 2024
94b4fc6
Merge branch 'feature-8.3' into ROU-10906
brandyscarney Aug 26, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion core/api.txt
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,7 @@ 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
2 changes: 1 addition & 1 deletion core/src/components.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -623,7 +623,7 @@ export namespace Components {
/**
* 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.
*/
"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
8 changes: 8 additions & 0 deletions core/src/components/checkbox/checkbox.scss
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,9 @@
flex-grow: 1;

align-items: center;
justify-content: space-between;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is required so that the user can still do the following, with a space between the label and checkbox:

<ion-checkbox style="width: 100%">Label</ion-checkbox>


width: 100%;
height: inherit;

cursor: inherit;
Expand Down Expand Up @@ -147,6 +149,12 @@ input {
// Justify Content
// ---------------------------------------------

:host(.checkbox-justify-space-between),
:host(.checkbox-justify-start),
:host(.checkbox-justify-end) {
display: flex;
}

:host(.checkbox-justify-space-between) .checkbox-wrapper {
justify-content: space-between;
}
Expand Down
4 changes: 2 additions & 2 deletions core/src/components/checkbox/checkbox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ export class Checkbox implements ComponentInterface {
* `"space-between"`: The label and checkbox will appear on opposite
* ends of the line with space between the two elements.
*/
@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.
Expand Down Expand Up @@ -194,7 +194,7 @@ export class Checkbox implements ComponentInterface {
'checkbox-disabled': disabled,
'checkbox-indeterminate': indeterminate,
interactive: true,
[`checkbox-justify-${justify}`]: true,
[`checkbox-justify-${justify}`]: justify !== undefined,
[`checkbox-alignment-${alignment}`]: true,
[`checkbox-label-placement-${labelPlacement}`]: true,
})}
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>
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The justify property does not need to be on this test as all it does is force the Checkbox to be 100% width when it isn't necessary.

<ion-checkbox checked>Checked</ion-checkbox>
`,
config
);
Expand Down
38 changes: 18 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,18 @@ 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: 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>
Copy link
Member Author

@brandyscarney brandyscarney Aug 22, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

An explicit width is no longer needed since using justify sets display: block which takes up the full-width of its container.

<ion-checkbox label-placement="start" justify="start">Label</ion-checkbox>
`,
config
);
Expand All @@ -27,7 +25,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 +37,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 +49,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`));
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Renamed this test to match the other prefixes in this describe block.

});
});

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 +77,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 +89,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 +103,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 +115,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 +127,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 +141,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 +153,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 +170,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
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These width differences are expected since removing the explicit width: 200px makes the checkbox take up the full width with justify defined.

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.
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.
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These width differences are expected since removing the explicit width: 200px makes the checkbox take up the inline width without justify defined.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was renamed to checkbox-label-start-justify-start-long-label

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.
Loading