テキスト入力の両側にテキスト、ボタン、またはボタン グループを追加することで、フォーム コントロールを簡単に拡張できます。
<div>
<b-input-group size="lg" prepend="$" append=".00">
<b-form-input></b-form-input>
</b-input-group>
<b-input-group class="mt-3">
<template #append>
<b-input-group-text><strong class="text-danger">!</strong></b-input-group-text>
</template>
<b-form-input></b-form-input>
</b-input-group>
<b-input-group prepend="Username" class="mt-3">
<b-form-input></b-form-input>
<b-input-group-append>
<b-button variant="outline-success">Button</b-button>
<b-button variant="info">Button</b-button>
</b-input-group-append>
</b-input-group>
</div>
使用方法
プロパティ、名前付きスロット、またはサブコンポーネントを使用してアドオンを添付できます。
prepend
プロパティと append
プロパティを使用する
値は内部的に <b-input-group-text>
でラップされ、正しく表示されます。
<div>
<b-input-group prepend="$" append=".00">
<b-form-input></b-form-input>
</b-input-group>
<b-input-group prepend="0" append="100" class="mt-3">
<b-form-input type="range" min="0" max="100"></b-form-input>
</b-input-group>
</div>
名前付きスロットを使用する
アドオンをより細かく制御したい場合は、代わりに prepend
スロットと append
スロットを使用できます。
スロットのコンテンツは、正しく表示されるように <b-input-group-prepend>
または <b-input-group-append>
によって自動的にラップされます。
<div>
<b-input-group>
<template #prepend>
<b-input-group-text >Username</b-input-group-text>
</template>
<b-form-input></b-form-input>
<template #append>
<b-dropdown text="Dropdown" variant="success">
<b-dropdown-item>Action A</b-dropdown-item>
<b-dropdown-item>Action B</b-dropdown-item>
</b-dropdown>
</template>
</b-input-group>
</div>
サブコンポーネントを使用する
<b-input-group-prepend>
または <b-input-group-append>
を使用して、任意のアドオンを好きな場所に 追加し、これらのコンポーネントを使用して入力グループ内のボタンをグループ化します。単一のボタンは、適切なスタイル設定のために、常にこれらのコンポーネントでラップする必要があります。
<div>
<b-input-group>
<b-input-group-prepend>
<b-button variant="outline-info">Button</b-button>
</b-input-group-prepend>
<b-form-input type="number" min="0.00"></b-form-input>
<b-input-group-append>
<b-button variant="outline-secondary">Button</b-button>
<b-button variant="outline-primary">Button</b-button>
<b-input-group-text>
<b-icon icon="x" />
</b-input-group-text>
</b-input-group-append>
</b-input-group>
</div>
コンテンツがテキスト形式の場合は、<b-input-group-prepend>
または <b-input-group-append>
に is-text
プロパティを設定して、適切なスタイルを適用します。または、<b-input-group-prepend>
または <b-input-group-append>
の中に <b-input-group-text>
サブコンポーネントを配置します。これは、BootstrapVue のアイコン のいずれかを使用する場合にも適用されます。
以下は、入力グループの*メイン*入力要素としてサポートされているフォーム コントロールです。
注意事項
- BootstrapVue は、
size
が指定された <b-input-group>
に配置された場合に、<b-form-file>
入力のサイズ変更を処理するために、カスタム SCSS/CSS を使用します。 - BootstrapVue は、
<b-form-input type="range">
が <b-input-group>
に配置された場合に、カスタム SCSS/CSS を使用します。 - BootstrapVue のカスタムコンポーネント (つまり、
<b-form-spinbutton>
、<b-form-rating>
、<b-form-tags>
など) には、BootstrapVue のカスタム SCSS/CSS が必要です。
チェックボックスとラジオボタンのアドオン
テキストの代わりに、入力グループのアドオン内にチェックボックスまたはラジオボタンを配置します。
**注記:** Bootstrap v4.x では、カスタム ラジオボタンとチェックボックスではなく、ネイティブのラジオボタンとチェックボックス入力を使用することを推奨していますが、<b-form-radio>
および <b-form-checkbox>
をいくつかのユーティリティクラスを適用して使用することも可能です。
ネイティブ チェックボックスとラジオボタン アドオン
<div>
<b-input-group class="mb-2">
<b-input-group-prepend is-text>
<input type="checkbox" aria-label="Checkbox for following text input">
</b-input-group-prepend>
<b-form-input aria-label="Text input with checkbox"></b-form-input>
</b-input-group>
<b-input-group>
<b-input-group-prepend is-text>
<input type="radio" aria-label="Radio for following text input">
</b-input-group-prepend>
<b-form-input aria-label="Text input with radio input"></b-form-input>
</b-input-group>
</div>
カスタム ラジオボタン、チェックボックス、およびスイッチ アドオン
アドオンとして <b-form-checkbox>
および <b-form-radio>
コンポーネントを使用し、Bootstrap ユーティリティクラス を使用して追加のスタイルを適用し、アドオンに「適合」させます。
<div>
<b-input-group class="mb-2">
<b-input-group-prepend is-text>
<b-form-checkbox class="mr-n2">
<span class="sr-only">Checkbox for following text input</span>
</b-form-checkbox>
</b-input-group-prepend>
<b-form-input aria-label="Text input with checkbox"></b-form-input>
</b-input-group>
<b-input-group class="mb-2">
<b-input-group-prepend is-text>
<b-form-radio class="mr-n2">
<span class="sr-only">Radio for following text input</span>
</b-form-radio>
</b-input-group-prepend>
<b-form-input aria-label="Text input with radio input"></b-form-input>
</b-input-group>
<b-input-group>
<b-input-group-prepend is-text>
<b-form-checkbox switch class="mr-n2">
<span class="sr-only">Switch for following text input</span>
</b-form-checkbox>
</b-input-group-prepend>
<b-form-input aria-label="Text input with switch"></b-form-input>
</b-input-group>
</div>
上記の例では、<span>
に .sr-only
クラスを使用して、カスタム コントロールのラベル コンテンツを視覚的に非表示にし (スクリーン リーダー ユーザーにはアクセスできるようにしたまま)、ユーティリティクラス .mr-n2
を使用して負の右マージンを追加し、コントロールと非表示のラベルの間の「ガター」スペースを補正しています。
<div>
<b-input-group prepend="First and last name" class="mb-2">
<b-form-input aria-label="First name"></b-form-input>
<b-form-input aria-label="Last name"></b-form-input>
</b-input-group>
</div>
複数のアドオン
複数のアドオンがサポートされており、チェックボックスとラジオボタン入力バージョンと組み合わせることができます。
<div>
<b-input-group prepend="Item">
<b-input-group-prepend is-text>
<input type="checkbox" aria-label="Checkbox for following text input">
</b-input-group-prepend>
<b-input-group-prepend is-text><b>$</b></b-input-group-prepend>
<b-form-input type="number" aria-label="Text input with checkbox"></b-form-input>
</b-input-group>
</div>
ドロップダウン アドオン
<div>
<b-input-group>
<template #prepend>
<b-dropdown text="Dropdown" variant="info">
<b-dropdown-item>Action A</b-dropdown-item>
<b-dropdown-item>Action B</b-dropdown-item>
</b-dropdown>
</template>
<b-form-input></b-form-input>
<template #append>
<b-dropdown text="Dropdown" variant="outline-secondary" v-for="i in 2" :key="i">
<b-dropdown-item>Action C</b-dropdown-item>
<b-dropdown-item>Action D</b-dropdown-item>
</b-dropdown>
</template>
</b-input-group>
</div>
コントロールのサイズ変更
size
プロパティを sm
または lg
に設定して、それぞれ小または大の高さに設定します。個々の入力またはボタンにサイズを設定する必要はありません。ただし、ドロップダウンにもサイズを設定する*必要があります*。
<div>
<b-input-group
v-for="size in ['sm','','lg']"
:key="size"
:size="size"
class="mb-3"
prepend="Label"
>
<b-form-input></b-form-input>
<b-input-group-append>
<b-button size="sm" text="Button" variant="success">Button</b-button>
</b-input-group-append>
</b-input-group>
</div>
幅を制御するには、入力を標準の Bootstrap グリッド列内に配置します。
カスタム ラジオボタン、チェックボックス、およびスイッチ アドオンのサイズ変更
アドオンとして <b-form-radio>
または <b-form-checkbox>
を使用する場合、選択したサイズによっては、すべてを正しく適合させるために追加のユーティリティクラスが必要になる場合があります。
<div>
<b-input-group size="sm" prepend="Small" class="mb-2">
<b-form-input aria-label="Small text input with custom switch"></b-form-input>
<b-input-group-append is-text>
<b-form-checkbox switch class="mr-n2 mb-n1">
<span class="sr-only">Checkbox for previous text input</span>
</b-form-checkbox>
</b-input-group-append>
</b-input-group>
<b-input-group size="lg" prepend="Large" class="mb-2">
<b-form-input aria-label="Large text input with switch"></b-form-input>
<b-input-group-append is-text>
<b-form-checkbox switch class="mr-n2">
<span class="sr-only">Switch for previous text input</span>
</b-form-checkbox>
</b-input-group-append>
</b-input-group>
</div>
具体的には、<b-input-group>
で sm
サイズを使用する場合、.mb-n1
ユーティリティクラス を使用して、負の下マージンを追加する必要があります。
コンテキスト状態
Bootstrap v4 は現在、入力グループのコンテキスト状態のスタイル設定 (つまり、有効または無効) を**サポートしていません**。ただし、入力グループ内の入力はコンテキスト状態をサポートしています。