Ion-list with label and note - note in next like text is very large

Hello,

I’m using the latest ionic in vanilla JS and it works out fine, however I’ve this piece of code to generate a list of items:

return `<ion-item>
                <ion-label>${name}</ion-label>
                <ion-note color="medium">${value}</ion-note>
            </ion-item>`;

It works fine in most cases, however sometimes the output note is very large resulting in this:

e

Is there a way to make it behave like native iOS where if it doesn’t fit the note will be displayed on a new line? Here’s the example from iOS settings:

Thank you.

You could force it to always be two lines by applying position="stacked" to your ion-label.

Otherwise, you’ve gotta edit the Shadow DOM and apply flex-wrap: wrap. Here is a Vue example but should work for regular JS too.

<template>
  <ion-item>
    <ion-label>Basic Item</ion-label>
  </ion-item>

  <ion-item class="two-lines">
    <ion-label style="text-wrap: nowrap;">Multi-line #1</ion-label>
    <ion-note>84505078084186484968498498408940894089408940894089</ion-note>
  </ion-item>

  <ion-item class="two-lines">
    <ion-label style="text-wrap: nowrap;">Multi-line #2</ion-label>
    <ion-note>84505078084186484968498498408940894089408940894089</ion-note>
  </ion-item>
</template>

<script lang="ts" setup>
import { IonItem, IonLabel, IonNote } from '@ionic/vue';
import { onMounted } from 'vue';

onMounted(() => {
  const sheet = new CSSStyleSheet();
  sheet.replaceSync('.input-wrapper { flex-wrap: wrap; }');

  document.querySelectorAll('ion-item.two-lines').forEach((element) => {
    element.shadowRoot.adoptedStyleSheets.push(sheet);
  });
});
</script>
1 Like

Stacked works, had to had a margin-bottom to the notes to make it look good.

The only thing missing was an option to stack dynamically like in native iOS. :slight_smile:

Thank you for the tip!

1 Like