Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Multiline ion-item with ion-toggle

Using Ionic 3.19.1. I want to create ion-items with one icon on the left, two lines on the middle and one ion-toggle at the end.

With two icons, it works perfectly:

two icons with two text lines

I did that with this code:

  <ion-list>
    <ion-item>
      <ion-icon name="american-football" item-start></ion-icon>
      <h2>prefs_transversal_products</h2>
      <p>prefs_transversal_products_desc</p>
      <!-- <ion-toggle color="secondary" item-end></ion-toggle>  -->
      <ion-icon name="american-football" item-end></ion-icon>
    </ion-item>
  </ion-list>

But if I enable the ion-toggle, the two lines of text disappear like this:

lines missing

What am I missing?

Thank you.

like image 542
flags Avatar asked Feb 02 '18 01:02

flags


People also ask

How do I add multiple toggles in ionic?

Most of the time when you want to add more than one element of the same kind in Ionic, the best way is to use list items. The class that is used for multiple toggles is the item-toggle.

Which class is used for multiple toggles in a list?

The class that is used for multiple toggles is the item-toggle. The next example shows how to create a list for toggles. The first one and the second one are checked. All the Ionic color classes can be applied to the toggle element.

Does the lines attribute work on the ion-list ion-item component?

Thanks for the issue! The lines attribute works on both the ion-list ion-item component. Our documentation for that is here: If you could point to where our documentation is incorrect that would be helpful. I'm not necessarily saying the documentation isn't correct.

What does the <input type> value of a toggle mean?

The value of a toggle is analogous to the value of a <input type="checkbox"> , it's only used when the toggle participates in a native <form>. Emitted when the toggle loses focus.


1 Answers

I can reproduce your issue, not quite sure what's going on there. Might be a bug.

Anyway, wrapping your text in an <ion-label> solves the problem for me:

<ion-list>
    <ion-item text-wrap>
        <ion-icon name="american-football" item-start></ion-icon>
        <ion-label>
            <h2>prefs_transversal_products</h2>
            <p>prefs_transversal_products_desc</p>
        </ion-label>
        <ion-toggle color="secondary" item-end></ion-toggle>
    </ion-item>
</ion-list>

result

See the docs for advanced usage of <ion-item> for additional info.

like image 141
Phonolog Avatar answered Oct 19 '22 02:10

Phonolog