Skip to content

Commit 0332c8c

Browse files
feat(toggle): display as block when justify or alignment properties are defined (#29802)
- Change the toggle'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 toggle with `width: 100%` set without `justify` or `alignment` set will still have the same default - Set the default `align-items` style to `center` so that a toggle with `width: 100%` and `label-placement="stacked"` 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 - Adds one example to the `label` e2e test of a long label that uses `justify` to ensure it still wraps properly
1 parent 4ccd15e commit 0332c8c

File tree

181 files changed

+223
-158
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

181 files changed

+223
-158
lines changed

core/api.txt

+2-2
Original file line numberDiff line numberDiff line change
@@ -1922,12 +1922,12 @@ ion-toast,part,icon
19221922
ion-toast,part,message
19231923

19241924
ion-toggle,shadow
1925-
ion-toggle,prop,alignment,"center" | "start",'center',false,false
1925+
ion-toggle,prop,alignment,"center" | "start" | undefined,undefined,false,false
19261926
ion-toggle,prop,checked,boolean,false,false,false
19271927
ion-toggle,prop,color,"danger" | "dark" | "light" | "medium" | "primary" | "secondary" | "success" | "tertiary" | "warning" | string & Record<never, never> | undefined,undefined,false,true
19281928
ion-toggle,prop,disabled,boolean,false,false,false
19291929
ion-toggle,prop,enableOnOffLabels,boolean | undefined,config.get('toggleOnOffLabels'),false,false
1930-
ion-toggle,prop,justify,"end" | "space-between" | "start",'space-between',false,false
1930+
ion-toggle,prop,justify,"end" | "space-between" | "start" | undefined,undefined,false,false
19311931
ion-toggle,prop,labelPlacement,"end" | "fixed" | "stacked" | "start",'start',false,false
19321932
ion-toggle,prop,mode,"ios" | "md",undefined,false,false
19331933
ion-toggle,prop,name,string,this.inputId,false,false

core/src/components.d.ts

+6-6
Original file line numberDiff line numberDiff line change
@@ -3214,9 +3214,9 @@ export namespace Components {
32143214
}
32153215
interface IonToggle {
32163216
/**
3217-
* How to control the alignment of the toggle 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.
3217+
* How to control the alignment of the toggle 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 toggle `display` to `block`.
32183218
*/
3219-
"alignment": 'start' | 'center';
3219+
"alignment"?: 'start' | 'center';
32203220
/**
32213221
* If `true`, the toggle is selected.
32223222
*/
@@ -3234,9 +3234,9 @@ export namespace Components {
32343234
*/
32353235
"enableOnOffLabels": boolean | undefined;
32363236
/**
3237-
* How to pack the label and toggle within a line. `"start"`: The label and toggle will appear on the left in LTR and on the right in RTL. `"end"`: The label and toggle will appear on the right in LTR and on the left in RTL. `"space-between"`: The label and toggle will appear on opposite ends of the line with space between the two elements.
3237+
* How to pack the label and toggle within a line. `"start"`: The label and toggle will appear on the left in LTR and on the right in RTL. `"end"`: The label and toggle will appear on the right in LTR and on the left in RTL. `"space-between"`: The label and toggle will appear on opposite ends of the line with space between the two elements. Setting this property will change the toggle `display` to `block`.
32383238
*/
3239-
"justify": 'start' | 'end' | 'space-between';
3239+
"justify"?: 'start' | 'end' | 'space-between';
32403240
/**
32413241
* Where to place the label relative to the input. `"start"`: The label will appear to the left of the toggle in LTR and to the right in RTL. `"end"`: The label will appear to the right of the toggle 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 toggle regardless of the direction. The alignment of the label can be controlled with the `alignment` property.
32423242
*/
@@ -8020,7 +8020,7 @@ declare namespace LocalJSX {
80208020
}
80218021
interface IonToggle {
80228022
/**
8023-
* How to control the alignment of the toggle 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.
8023+
* How to control the alignment of the toggle 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 toggle `display` to `block`.
80248024
*/
80258025
"alignment"?: 'start' | 'center';
80268026
/**
@@ -8040,7 +8040,7 @@ declare namespace LocalJSX {
80408040
*/
80418041
"enableOnOffLabels"?: boolean | undefined;
80428042
/**
8043-
* How to pack the label and toggle within a line. `"start"`: The label and toggle will appear on the left in LTR and on the right in RTL. `"end"`: The label and toggle will appear on the right in LTR and on the left in RTL. `"space-between"`: The label and toggle will appear on opposite ends of the line with space between the two elements.
8043+
* How to pack the label and toggle within a line. `"start"`: The label and toggle will appear on the left in LTR and on the right in RTL. `"end"`: The label and toggle will appear on the right in LTR and on the left in RTL. `"space-between"`: The label and toggle will appear on opposite ends of the line with space between the two elements. Setting this property will change the toggle `display` to `block`.
80448044
*/
80458045
"justify"?: 'start' | 'end' | 'space-between';
80468046
/**

core/src/components/toggle/test/basic/index.html

+21-8
Original file line numberDiff line numberDiff line change
@@ -12,25 +12,38 @@
1212
<script src="../../../../../scripts/testing/scripts.js"></script>
1313
<script nomodule src="../../../../../dist/ionic/ionic.js"></script>
1414
<script type="module" src="../../../../../dist/ionic/ionic.esm.js"></script>
15+
16+
<style>
17+
ion-toggle {
18+
margin-bottom: 8px;
19+
}
20+
21+
hr {
22+
background: #ddd;
23+
}
24+
</style>
1525
</head>
1626

1727
<body>
1828
<ion-app>
1929
<ion-header>
2030
<ion-toolbar>
2131
<ion-title>Toggle - Basic</ion-title>
22-
<ion-buttons slot="primary">
23-
<ion-toggle aria-label="Enable Notifications"></ion-toggle>
24-
</ion-buttons>
2532
</ion-toolbar>
2633
</ion-header>
2734

2835
<ion-content class="ion-padding">
29-
<ion-toggle
30-
>Enable Notifications Enable Notifications Enable Notifications Enable Notifications Enable Notifications
31-
Enable Notifications Enable Notifications Enable Notifications Enable Notifications Enable
32-
Notifications</ion-toggle
33-
>
36+
<ion-toggle>Unchecked</ion-toggle><br />
37+
<ion-toggle checked>Checked</ion-toggle><br />
38+
<ion-toggle disabled>Disabled</ion-toggle><br />
39+
<ion-toggle disabled checked>Disabled, Checked</ion-toggle><br />
40+
41+
<hr />
42+
43+
<ion-toggle> Default width </ion-toggle><br />
44+
<ion-toggle style="width: 200px"> Specified width </ion-toggle><br />
45+
<ion-toggle style="width: 100%"> Full-width </ion-toggle><br />
46+
<ion-toggle> Long Label Long Label Long Label Long Label Long Label Long Label </ion-toggle><br />
3447
</ion-content>
3548
</ion-app>
3649
</body>

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

-4
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,6 @@
3333
padding: 0;
3434
}
3535
}
36-
37-
ion-toggle {
38-
width: 100%;
39-
}
4036
</style>
4137
</head>
4238

0 commit comments

Comments
 (0)