From 5b7e422dc0bfd4d58fb31f62715af47e62dabb57 Mon Sep 17 00:00:00 2001 From: Sean Perkins <13732623+sean-perkins@users.noreply.github.com> Date: Tue, 19 Sep 2023 23:27:36 -0400 Subject: [PATCH] fix(radio,toggle,checkbox,select): padded space is clickable in items (#28136) Issue number: Resolves #27169 --------- ## What is the current behavior? Clicking the padded space within an `ion-item` will not pass the click event to the slotted `ion-radio`, `ion-checkbox`, `ion-select` or `ion-toggle`. ## What is the new behavior? - The padded space at the start of `.item-native` and at the end of `.item-inner` is clickable to activate a control. - When the item is clicked, we check if the event is a result of clicking the control or clicking the item's padded space. If the click event is on the control, we don't need to do anything and let the default behavior occur. If the click event is on the padded space, we manually call the `.click()` method for the interactive element. - The cursor pointer displays when hovering over the padded space when a slotted interactive control is present. ## Does this introduce a breaking change? - [ ] Yes - [x] No ## Other information --- core/src/components/checkbox/checkbox.tsx | 11 +++- .../checkbox/test/basic/checkbox.e2e.ts | 23 ++++++++ .../test/legacy/basic/checkbox.e2e.ts | 23 ++++++++ core/src/components/item/item.scss | 8 +++ core/src/components/item/item.tsx | 58 ++++++++++++++++--- .../components/radio/test/item/radio.e2e.ts | 29 ++++++++++ .../select/test/basic/select.e2e.ts | 28 +++++++++ .../components/toggle/test/item/toggle.e2e.ts | 34 +++++++++++ core/src/components/toggle/toggle.tsx | 2 +- 9 files changed, 205 insertions(+), 11 deletions(-) diff --git a/core/src/components/checkbox/checkbox.tsx b/core/src/components/checkbox/checkbox.tsx index cf463bfbf55..a90ed53c458 100644 --- a/core/src/components/checkbox/checkbox.tsx +++ b/core/src/components/checkbox/checkbox.tsx @@ -140,9 +140,8 @@ export class Checkbox implements ComponentInterface { */ @Event() ionStyle!: EventEmitter; - // TODO(FW-3100): remove this connectedCallback() { - this.legacyFormController = createLegacyFormController(this.el); + this.legacyFormController = createLegacyFormController(this.el); // TODO(FW-3100): remove this } componentWillLoad() { @@ -195,7 +194,7 @@ export class Checkbox implements ComponentInterface { }); }; - private toggleChecked = (ev: any) => { + private toggleChecked = (ev: Event) => { ev.preventDefault(); this.setFocus(); @@ -211,6 +210,10 @@ export class Checkbox implements ComponentInterface { this.ionBlur.emit(); }; + private onClick = (ev: MouseEvent) => { + this.toggleChecked(ev); + }; + // TODO(FW-3100): run contents of renderCheckbox directly instead render() { const { legacyFormController } = this; @@ -252,6 +255,7 @@ export class Checkbox implements ComponentInterface { [`checkbox-alignment-${alignment}`]: true, [`checkbox-label-placement-${labelPlacement}`]: true, })} + onClick={this.onClick} >