feat(toggle): expose label wrapper as shadow part (#28585)

This commit is contained in:
Liam DeBeasi
2023-11-30 14:03:51 -05:00
committed by GitHub
parent 52ed2bf637
commit a34188f7db
4 changed files with 16 additions and 7 deletions

View File

@ -1515,6 +1515,7 @@ ion-toggle,css-prop,--handle-width
ion-toggle,css-prop,--track-background
ion-toggle,css-prop,--track-background-checked
ion-toggle,part,handle
ion-toggle,part,label
ion-toggle,part,track
ion-toolbar,shadow

View File

@ -40,6 +40,19 @@ describe('toggle', () => {
expect(t.enableOnOffLabels).toBe(true);
});
});
describe('shadow parts', () => {
it('should have shadow parts', async () => {
const page = await newSpecPage({
components: [Toggle],
html: `<ion-toggle>Label</ion-toggle>`,
});
const toggle = page.body.querySelector('ion-toggle')!;
expect(toggle).toHaveShadowPart('label');
expect(toggle).toHaveShadowPart('track');
expect(toggle).toHaveShadowPart('handle');
});
});
});
describe('ion-toggle: disabled', () => {

View File

@ -105,13 +105,6 @@ input {
// ----------------------------------------------------------------
.label-text-wrapper {
/**
* This ensures that double tapping this text
* clicks the <label> and focuses the input
* when a screen reader is enabled.
*/
pointer-events: none;
text-overflow: ellipsis;
white-space: nowrap;

View File

@ -23,6 +23,7 @@ import type { ToggleChangeEventDetail } from './toggle-interface';
*
* @part track - The background track of the toggle.
* @part handle - The toggle handle, or knob, used to change the checked state.
* @part label - The label text describing the toggle.
*/
@Component({
tag: 'ion-toggle',
@ -377,6 +378,7 @@ export class Toggle implements ComponentInterface {
'label-text-wrapper': true,
'label-text-wrapper-hidden': !this.hasLabel,
}}
part="label"
>
<slot></slot>
</div>