ionic-framework icon indicating copy to clipboard operation
ionic-framework copied to clipboard

bug: ion-checkbox is toggled by ion-item click

Open bsbechtel opened this issue 5 years ago • 3 comments

Bug Report

Ionic version:

[x] 4.x

Current behavior:

If you have the following markup, any click or tap on the ion-item will toggle the ion-checkbox:

    <ion-item>
      <ion-checkbox slot="start"></ion-checkbox>
      <div>Testing!</div>
    </ion-item>

Expected behavior:

The ion-checkbox should only toggle when it is clicked, or the click event from the ion-item should be cancellable.

Steps to reproduce:

Related code:

Codepen

Other information:

This issue has been brought up multiple times and not fixed: 19590 15850 17832

Ionic info:

insert the output from ionic info here

bsbechtel avatar Feb 17 '20 19:02 bsbechtel

@bsbechtel Imho it is very ok, that checkbox is toggled when item clicked - think about mobile apps, it is proper behavior, that is from the very beginning of ionic. But you can achieve what you need wrapping ion-checkbox in slotted div:

<div slot="start" style="position: relative"><ion-checkbox></ion-checkbox></div>

MarkChrisLevy avatar Feb 19 '20 16:02 MarkChrisLevy

Thanks for the issue! This is the intended behavior for mobile devices to match the native behavior. However, as a workaround you could use the following: https://codepen.io/brandyscarney/pen/vYNeLzZ?editors=1100

ion-item {
  --background-hover: none;
  --background-activated: none;
  --ripple-color: transparent;
}

ion-checkbox {
  position: relative;
}

What this does:

  • Removes the hover / activated states & ripple effect from item so it doesn't appear clickable
  • Sets checkbox position to relative which will move the checkbox click to only appear over the checkbox itself (this is essentially what happens when a user adds multiple checkboxes in an item)

I'm going to mark this as a needs: design decision as we will need to discuss the API for disabling this behavior in the framework.

brandyscarney avatar Apr 30 '20 22:04 brandyscarney

In my case the checkbox is only toggled on the first item on the ios style. The second item it is only toggled when I tap on the checkbox (thats what i want).

I think both cases are valid but it should be consistent.

gkTim avatar May 07 '20 08:05 gkTim