v-ons-list

リストを表現するためのコンポーネント。ons-list-itemのコンテナとして使用します。

実例

Lists

Creating lists in Onsen UI is very simple and they are one of the most important UI components in mobile apps.

Onsen UI provides three elements for creating lists:

  • <v-ons-list>
  • <v-ons-list-item>
  • <v-ons-list-header>
  • <ons-list-title>

Markup

The <v-ons-list> is used as the parent and for every item one <v-ons-list-item> element is used:

<v-ons-list>
  <v-ons-list-item>Item A</v-ons-list-item>
  <v-ons-list-item>Item B</v-ons-list-item>
  <v-ons-list-item>Item C</v-ons-list-item>
</v-ons-list>

This will render as a list with three items.

Headers and titles

To group items together you can use the <v-ons-list-header> element to create a header with text content. The whole list can be preceded by a <v-ons-list-title> element.

<v-ons-list-title>People I know</v-ons-list-title>
<v-ons-list>
  <v-ons-list-header>My friends</v-ons-list-header>
  <v-ons-list-item>Alice</v-ons-list-item>
  <v-ons-list-item>Bob</v-ons-list-item>
  <v-ons-list-item>Eve</v-ons-list-item>

  <v-ons-list-header>My enemies</v-ons-list-header>
  <v-ons-list-item>Alice</v-ons-list-item>
  <v-ons-list-item>Bob</v-ons-list-item>
  <v-ons-list-item>Eve</v-ons-list-item>
</v-ons-list>

You can use as many headers as you want in the same list.

List item structure

In the previous examples the list items only contained simple text content. Onsen UI list items provide a secondary syntax where the list item is divided into four sections.

This can be used to add icons, thumbnails or even form elements to your list items:

<v-ons-list-item>
  <div class="left">
    <v-ons-icon icon="md-face" class="list-item__icon"></v-ons-icon>
  </div>
  <div class="center">
    Icon and switch
  </div>
  <div class="right">
    <v-ons-switch></v-ons-switch>
  </div>
  <div class="expandable-content">
    Expandable content
  </div>
</v-ons-list-item>

Notice that the inner structure does not need to be made with div elements. It can be any element such as a label.

Apart from this, some extra classes are provided to style different parts of the list items:

  • list-item__title: Title inside the central part. Modifies font and position.
  • list-item__subtitle: Subtitle inside the central part. Modifies font and position.
  • list-item__icon: List item icon. Modifies size and alignment.
  • list-item__thumbnail: List item thumbnail. Modifies size, borders and alignment.
<v-ons-list-item>
  <div class="left">
    <img class="list-item__thumbnail" src="https://placekitten.com/g/40/40">
  </div>
  <div class="center">
    <span class="list-item__title">Cutest kitty</span>
    <span class="list-item__subtitle">On the Internet</span>
  </div>
</v-ons-list-item>

Expandable list items

You can create list items that expand to reveal extra content when tapped by setting the expandable attribute. The content that is shown when the list item is expanded is defined in a div.expandable-content.

<v-ons-list-item expandable>
  Tap to expand
  <div class="expandable-content">This is shown when expanded</div>
</v-ons-list-item>

If div.right is not defined, a dropdown arrow is automatically added to the right side of the expandable list item.

The list item can also be expanded and contracted by setting the value of expanded.

The tappable attribute

The tappable attribute is used to give the user an indication when they tap a list item. In iOS the background color will change when tapped and on Android it will display the Material Design ripple effect.

<v-ons-list-item tappable>Tap me!</v-ons-list-item>

This is very useful in apps that perform some action or navigate to a new page when a list item is tapped.

In order to prevent tappable effect when tapping on specific child elements like custom buttons, prevent-tap attribute can be added to any of the children. v-ons-* elements like v-ons-button or v-ons-checkbox are ignored by default.

Modifiers

There is a bunch of modifiers that can be used to customize the look of the lists and list items.

In Onsen UI modifiers are applied by adding the modifier attribute to an element. More than one can be added by separating them with spaces.

For example, to create an inset list you can use the inset modifier on the <ons-list> element:

<v-ons-list modifier="inset">
  ...
</v-ons-list>

Changing the divider

The longdivider and nodivider modifiers can be used to change the length or remove the divider (horizontal line) between list items completely. The default style for list items is a divider that doesn’t completely cover the whole screen. Instead it has some padding on the left to make it look more similar to native lists.

By adding the nodivider modifier the divider can be removed:

<v-ons-list>
  <v-ons-list-item modifier="nodivider">Item A</v-ons-list-item>
  <v-ons-list-item modifier="nodivider">Item B</v-ons-list-item>
</v-ons-list>

関連情報

名前 型 / デフォルト値 概要
modifier String リストの表現を指定します。 Optional.
Name 概要
inset 親要素の画面いっぱいに広がらないリストを表示します。
noborder リストの上下のボーダーが無いリストを表示します。

お困りですか?

Onsen UIに関する質問は、Stack Overflowにてonsen-uiタグを付与してください。Onsen UIチームはあなたの問題解決をお手伝いします。

バグ報告や機能要望については、GitHub Issuesに記載をお願いいたします。

あわせて、下記の情報も参考にしてください。