Skip to content

Commit

Permalink
feat(toggle): display as block when justify or alignment properties a…
Browse files Browse the repository at this point in the history
…re 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
  • Loading branch information
brandyscarney committed Aug 28, 2024
1 parent 4ccd15e commit 0332c8c
Show file tree
Hide file tree
Showing 181 changed files with 223 additions and 158 deletions.
4 changes: 2 additions & 2 deletions core/api.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1922,12 +1922,12 @@ ion-toast,part,icon
ion-toast,part,message

ion-toggle,shadow
ion-toggle,prop,alignment,"center" | "start",'center',false,false
ion-toggle,prop,alignment,"center" | "start" | undefined,undefined,false,false
ion-toggle,prop,checked,boolean,false,false,false
ion-toggle,prop,color,"danger" | "dark" | "light" | "medium" | "primary" | "secondary" | "success" | "tertiary" | "warning" | string & Record<never, never> | undefined,undefined,false,true
ion-toggle,prop,disabled,boolean,false,false,false
ion-toggle,prop,enableOnOffLabels,boolean | undefined,config.get('toggleOnOffLabels'),false,false
ion-toggle,prop,justify,"end" | "space-between" | "start",'space-between',false,false
ion-toggle,prop,justify,"end" | "space-between" | "start" | undefined,undefined,false,false
ion-toggle,prop,labelPlacement,"end" | "fixed" | "stacked" | "start",'start',false,false
ion-toggle,prop,mode,"ios" | "md",undefined,false,false
ion-toggle,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 @@ -3214,9 +3214,9 @@ export namespace Components {
}
interface IonToggle {
/**
* 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.
* 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`.
*/
"alignment": 'start' | 'center';
"alignment"?: 'start' | 'center';
/**
* If `true`, the toggle is selected.
*/
Expand All @@ -3234,9 +3234,9 @@ export namespace Components {
*/
"enableOnOffLabels": boolean | undefined;
/**
* 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.
* 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`.
*/
"justify": 'start' | 'end' | 'space-between';
"justify"?: 'start' | 'end' | 'space-between';
/**
* 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.
*/
Expand Down Expand Up @@ -8020,7 +8020,7 @@ declare namespace LocalJSX {
}
interface IonToggle {
/**
* 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.
* 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`.
*/
"alignment"?: 'start' | 'center';
/**
Expand All @@ -8040,7 +8040,7 @@ declare namespace LocalJSX {
*/
"enableOnOffLabels"?: boolean | undefined;
/**
* 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.
* 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`.
*/
"justify"?: 'start' | 'end' | 'space-between';
/**
Expand Down
29 changes: 21 additions & 8 deletions core/src/components/toggle/test/basic/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,25 +12,38 @@
<script src="../../../../../scripts/testing/scripts.js"></script>
<script nomodule src="../../../../../dist/ionic/ionic.js"></script>
<script type="module" src="../../../../../dist/ionic/ionic.esm.js"></script>

<style>
ion-toggle {
margin-bottom: 8px;
}

hr {
background: #ddd;
}
</style>
</head>

<body>
<ion-app>
<ion-header>
<ion-toolbar>
<ion-title>Toggle - Basic</ion-title>
<ion-buttons slot="primary">
<ion-toggle aria-label="Enable Notifications"></ion-toggle>
</ion-buttons>
</ion-toolbar>
</ion-header>

<ion-content class="ion-padding">
<ion-toggle
>Enable Notifications Enable Notifications Enable Notifications Enable Notifications Enable Notifications
Enable Notifications Enable Notifications Enable Notifications Enable Notifications Enable
Notifications</ion-toggle
>
<ion-toggle>Unchecked</ion-toggle><br />
<ion-toggle checked>Checked</ion-toggle><br />
<ion-toggle disabled>Disabled</ion-toggle><br />
<ion-toggle disabled checked>Disabled, Checked</ion-toggle><br />

<hr />

<ion-toggle> Default width </ion-toggle><br />
<ion-toggle style="width: 200px"> Specified width </ion-toggle><br />
<ion-toggle style="width: 100%"> Full-width </ion-toggle><br />
<ion-toggle> Long Label Long Label Long Label Long Label Long Label Long Label </ion-toggle><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.
4 changes: 0 additions & 4 deletions core/src/components/toggle/test/label/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,6 @@
padding: 0;
}
}

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

Expand Down
Loading

0 comments on commit 0332c8c

Please sign in to comment.