Buttonはクリック可能な要素を提供し、Form内や、標準の単機能なButton機能を必要とする任意の場所で使用できます。text、icon、またはその両方を表示できます。Buttonは、いくつかの属性を利用して特定の外観になるようにスタイル設定できます。
基本的な使い方 html src/app/example.component.html example.component.html ts src/app/example.component.ts example.component.ts
< ion-button > Default </ ion-button > < ion-button [disabled] = " true " > Disabled </ ion-button > Expand このプロパティでは、ボタンの幅を指定することができます。デフォルトでは、ボタンは display: inline-block を持ちますが、このプロパティを設定すると、ボタンは display: block を持つ全角要素に変更されます。
html src/app/example.component.html example.component.html ts src/app/example.component.ts example.component.ts
< ion-button expand = " block " > Block </ ion-button > < ion-button expand = " full " > Full </ ion-button > Shape このプロパティは、ボタンの形状を指定することができます。デフォルトでは、ボタンは小さなボーダー半径を持つ長方形ですが、これを "round" に設定すると、ボタンは丸みを帯びた要素に変更されます。
html src/app/example.component.html example.component.html ts src/app/example.component.ts example.component.ts
< ion-button > Default </ ion-button >
< ion-button shape = " round " > Round </ ion-button >
< ion-button >
< ion-icon slot = " icon-only " name = " heart " > </ ion-icon >
</ ion-button >
< ion-button shape = " round " >
< ion-icon slot = " icon-only " name = " heart " > </ ion-icon >
</ ion-button > Fill この属性は、Buttonのbackgroundとborder-colorを設定します。デフォルトでは、Buttonはtoolbar内にない限り、backgroundは塗りつぶされます。toolbar内にある場合は、backgroundは透明になります。
html src/app/example.component.html example.component.html ts src/app/example.component.ts example.component.ts
< ion-button > Default </ ion-button >
< ion-button fill = " clear " > Clear </ ion-button >
< ion-button fill = " outline " > Outline </ ion-button >
< ion-button fill = " solid " > Solid </ ion-button > Size この属性は、Buttonのサイズを指定します。この属性を設定すると、Buttonの高さとpaddingが変更されます
html src/app/example.component.html example.component.html ts src/app/example.component.ts example.component.ts
< ion-button size = " small " > Small </ ion-button >
< ion-button size = " default " > Default </ ion-button >
< ion-button size = " large " > Large </ ion-button > Icons html src/app/example.component.html example.component.html ts src/app/example.component.ts example.component.ts
< ion-button size = " small " >
< ion-icon slot = " icon-only " ios = " logo-apple " md = " settings-sharp " > </ ion-icon >
</ ion-button >
< ion-button >
< ion-icon slot = " icon-only " ios = " logo-apple " md = " settings-sharp " > </ ion-icon >
</ ion-button >
< ion-button size = " large " >
< ion-icon slot = " icon-only " ios = " logo-apple " md = " settings-sharp " > </ ion-icon >
</ ion-button >
< ion-button size = " small " >
< ion-icon slot = " start " name = " star " > </ ion-icon >
Left Icon
</ ion-button >
< ion-button >
< ion-icon slot = " start " name = " star " > </ ion-icon >
Left Icon
</ ion-button >
< ion-button size = " large " >
< ion-icon slot = " start " name = " star " > </ ion-icon >
Left Icon
</ ion-button >
< ion-button size = " small " >
Right Icon
< ion-icon slot = " end " name = " heart " > </ ion-icon >
</ ion-button >
< ion-button >
Right Icon
< ion-icon slot = " end " name = " heart " > </ ion-icon >
</ ion-button >
< ion-button size = " large " >
Right Icon
< ion-icon slot = " end " name = " heart " > </ ion-icon >
</ ion-button > テーマ Colors html src/app/example.component.html example.component.html ts src/app/example.component.ts example.component.ts
< ion-button > Default </ ion-button >
< ion-button color = " primary " > Primary </ ion-button >
< ion-button color = " secondary " > Secondary </ ion-button >
< ion-button color = " tertiary " > Tertiary </ ion-button >
< ion-button color = " success " > Success </ ion-button >
< ion-button color = " warning " > Warning </ ion-button >
< ion-button color = " danger " > Danger </ ion-button >
< ion-button color = " light " > Light </ ion-button >
< ion-button color = " medium " > Medium </ ion-button >
< ion-button color = " dark " > Dark </ ion-button > CSSカスタムプロパティ html src/app/example.component.html example.component.html css src/app/example.component.css example.component.css ts src/app/example.component.ts example.component.ts
< ion-button > Custom Button </ ion-button > アクセシビリティ ボタンはアクセスしやすいように作られていますが、その内容によっては調整が必要な場合があります。ボタンコンポーネントは、ネイティブのbutton element をレンダリングし、ネイティブのボタンが提供する機能を利用できるようにします。
Overflowing Text Content ボタンのテキスト・コンテンツがコンテナからはみ出す場合が多々あります。このような場合、すべてのテキストがまだ読めるように、ボタンの内側にテキストを折り返すことをお勧めします。ボタンコンポーネントは、テキストの余分な行を収容するために、その高さを自動的に調整します。
テキストが長すぎて収まらない場合、ボタンテキストは自動的に次の行に折り返されません。テキストを折り返すには、ion-text-wrapクラスを追加して、white-spaceプロパティを"normal"に設定します。これは将来のメジャーリリースでデフォルトになる予定である。
備考
max-width`スタイルは、デモのためだけに下のボタンに設定されています。テキストラッピングは動的なボタン幅で動作します。
html src/app/example.component.html example.component.html ts src/app/example.component.ts example.component.ts
< ion-button > Default </ ion-button >
< ion-button class = " ion-text-wrap " style = " max-width : 400 px "
> This is the button that never ends it just goes on and on and on and on and on and on and on and on my
friends </ ion-button
> プロパティ Description ボタンの種類です。 Attribute button-typeType stringDefault 'button'
color Description アプリケーションのカラーパレットから使用する色を指定します。デフォルトのオプションは以下の通りです。 "primary", "secondary", "tertiary", "success", "warning", "danger", "light", "medium", と "dark" です.色に関する詳しい情報は theming を参照してください。 Attribute colorType "danger" | "dark" | "light" | "medium" | "primary" | "secondary" | "success" | "tertiary" | "warning" | string | undefinedDefault undefined
disabled Description trueの場合、ユーザはボタンと対話することができません。Attribute disabledType booleanDefault false
download Description この属性は、ブラウザが URL に移動する代わりに URL をダウンロードするように指示し、ユーザはローカルファイルとして保存するように促されます。この属性に値がある場合、保存のプロンプトであらかじめ入力されたファイル名として使用されます(ユーザーはファイル名を変更することができます)。 Attribute downloadType string | undefinedDefault undefined
expand Description 全角のボタンなら"block"、角が四角く左右のボーダーがない全角のボタンなら"full"に設定します。 Attribute expandType "block" | "full" | undefinedDefault undefined
fill Description フラットなボタンに似た透明なボタンには "clear" を、ボーダーのある透明なボタンには "outline" を、背景を塗りつぶしたボタンには "solid" を設定します。デフォルトの塗りつぶしは "solid" です。ただし、ツールバーの内側では "clear" となります。 Attribute fillType "clear" | "default" | "outline" | "solid" | undefinedDefault undefined
Description HTML のフォーム要素またはフォーム要素 ID。ボタンがフォームの子でない場合に、フォームを送信するために使用します。 This is a virtual property that is set once during initialization and will not update if you change its value after the initial render. Attribute formType HTMLFormElement | string | undefinedDefault undefined
href Description ハイパーリンクが指し示す URL または URL フラグメントを格納します。このプロパティが設定されている場合、アンカータグがレンダリングされます。 Attribute hrefType string | undefinedDefault undefined
mode Description modeは、どのプラットフォームのスタイルを使用するかを決定します。 This is a virtual property that is set once during initialization and will not update if you change its value after the initial render. Attribute modeType "ios" | "md"Default undefined
rel Description ターゲットオブジェクトとリンクオブジェクトの関係を指定します。値は、スペースで区切られたリンクタイプ のリストです。 Attribute relType string | undefinedDefault undefined
routerAnimation Description ルータを使用する場合、hrefを使用して別のページに移動する際の遷移アニメーションを指定します。 Attribute router-animationType ((baseEl: any, opts?: any) => Animation) | undefinedDefault undefined
routerDirection Description ルータを使用する場合、hrefを使用して他のページに移動する際の遷移方向を指定します。 Attribute router-directionType "back" | "forward" | "root"Default 'forward'
shape Description "round" に設定すると、より角が丸いボタンになります。Attribute shapeType "round" | undefinedDefault undefined
size Description ボタンの高さとPaddingが少ない場合は "small" に、ボタンの高さとPaddingがデフォルトの場合は "default" に、ボタンの高さとPaddingが多い場合は "large" に設定します。ただし、ボタンがアイテムの中にある場合は、デフォルトでサイズが "small" になっています。アイテムの内部でサイズを "default" に設定すると、標準サイズのボタンになります。 Attribute sizeType "default" | "large" | "small" | undefinedDefault undefined
strong Description trueの場合、より重いFont Weightを持つボタンをアクティブにします。Attribute strongType booleanDefault false
target Description リンク先のURLを表示する場所を指定します。hrefを指定した場合のみ適用される。特別なキーワードがあります。"_blank", "_self", "_parent", "_top". Attribute targetType string | undefinedDefault undefined
type Description ボタンの種類です。 Attribute typeType "button" | "reset" | "submit"Default 'button'
イベント Name Description Bubbles ionBlurボタンのフォーカスが外れたときに発行されます。 trueionFocusボタンにフォーカスが当たっているときに発行されます。 true
メソッド No public methods available for this component.
CSS Shadow Parts Name Description nativeすべての子要素をラップするネイティブHTMLのボタンまたはアンカー要素です。
CSSカスタムプロパティ iOS MD
Name Description --backgroundボタンの背景 --background-activatedボタンが押されたときの背景。注意:これを設定すると、Material Designの波紋に干渉します。 --background-activated-opacityボタンが押されたときの不透明度 --background-focusedタブキーでフォーカスしたときのボタンの背景 --background-focused-opacityタブキーでフォーカスしたときのボタンの不透明度 --background-hoverホバー時のボタンの背景 --background-hover-opacityホバー時の背景の不透明度 --border-colorボタンのボーダーカラー --border-radiusボタンの境界半径 --border-styleボタンのボーダースタイル --border-widthボタンのボーダー幅 --box-shadowボタンのボックスシャドウ --colorボタンの文字色 --color-activatedボタンが押されたときの文字色 --color-focusedタブキーでフォーカスしたときのボタンの文字色 --color-hoverホバー時のボタンの文字色 --opacityボタンの不透明度 --padding-bottomボタンのBottom Padding --padding-endボタンの向きが左から右の場合はRight Padding、右から左の場合はLeft Paddingとなります。 --padding-startボタンの向きが左から右の場合はLeft Padding、右から左の場合はRight Paddingとなります。 --padding-topボタンのTop Padding --ripple-colorボタンリプルエフェクトの色 --transitionボタンの遷移
Slots Name Description slotがない状態で提供される場合、コンテンツは名前付きslotの間に配置されます。 endコンテンツは、LTRの場合はボタンテキストの右側に、RTLの場合は左側に配置されます。 icon-onlyテキストを持たないボタン内のアイコンに対して使用されるべきです。 startコンテンツは、LTRではボタンテキストの左側に、RTLでは右側に配置されます。