Skip to content

Commit 43e2b39

Browse files
EinfachHansliamdebeasi
andauthoredOct 31, 2022
feat(toggle): add toggleOnOffLabels global config option (#26087)
Co-authored-by: Liam DeBeasi <liamdebeasi@users.noreply.github.com>
1 parent b364d58 commit 43e2b39

File tree

3 files changed

+50
-1
lines changed

3 files changed

+50
-1
lines changed
 
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import { newSpecPage } from '@stencil/core/testing';
2+
3+
import { config } from '../../../global/config';
4+
import { Toggle } from '../toggle';
5+
6+
describe('toggle', () => {
7+
beforeEach(() => {
8+
config.reset({});
9+
});
10+
11+
const newToggle = async (): Promise<Toggle> => {
12+
const { rootInstance } = await newSpecPage({
13+
components: [Toggle],
14+
html: `<ion-toggle></ion-toggle>`,
15+
});
16+
return rootInstance;
17+
};
18+
19+
describe('enableOnOffLabels', () => {
20+
it('should disable on/off labels when setting to false on component', async () => {
21+
const t = await newToggle();
22+
t.enableOnOffLabels = false;
23+
config.reset({
24+
toggleOnOffLabels: true,
25+
});
26+
expect(t.enableOnOffLabels).toBe(false);
27+
});
28+
29+
it('should enable on/off labels when setting to true on global config', async () => {
30+
config.reset({
31+
toggleOnOffLabels: true,
32+
});
33+
const t = await newToggle();
34+
expect(t.enableOnOffLabels).toBe(true);
35+
});
36+
37+
it('should enable on/off labels when setting to true on component', async () => {
38+
const t = await newToggle();
39+
t.enableOnOffLabels = true;
40+
expect(t.enableOnOffLabels).toBe(true);
41+
});
42+
});
43+
});

‎core/src/components/toggle/toggle.tsx

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import type { ComponentInterface, EventEmitter } from '@stencil/core';
22
import { Component, Element, Event, Host, Prop, State, Watch, h } from '@stencil/core';
33
import { checkmarkOutline, removeOutline, ellipseOutline } from 'ionicons/icons';
44

5+
import { config } from '../../global/config';
56
import { getIonMode } from '../../global/ionic-global';
67
import type { Color, Gesture, GestureDetail, Mode, StyleEventDetail, ToggleChangeEventDetail } from '../../interface';
78
import { getAriaLabel, renderHiddenInput } from '../../utils/helpers';
@@ -67,7 +68,7 @@ export class Toggle implements ComponentInterface {
6768
/**
6869
* Enables the on/off accessibility switch labels within the toggle.
6970
*/
70-
@Prop() enableOnOffLabels: boolean | undefined = undefined;
71+
@Prop() enableOnOffLabels: boolean | undefined = config.get('toggleOnOffLabels');
7172

7273
/**
7374
* Emitted when the value property has changed.

‎core/src/utils/config.ts

+5
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,11 @@ export interface IonicConfig {
6464
*/
6565
spinner?: SpinnerTypes;
6666

67+
/**
68+
* Overrides the default enableOnOffLabels in all `<ion-toggle>` components.
69+
*/
70+
toggleOnOffLabels?: boolean;
71+
6772
/**
6873
* Overrides the default spinner for all `ion-loading` overlays, ie. the ones
6974
* created with `ion-loading-controller`.

0 commit comments

Comments
 (0)
Please sign in to comment.