タグボックスコントロールの入力フィールドにフローティングラベルを表示する機能について解説します。
フローティングラベルを表示する方法
フローティングラベルを表示するには、floatingLabelTextプロパティにフローティングラベルの表示テキストを設定します。floatingLabelDirectionプロパティを設定することで、入力時にフローティングラベルを指定位置に移動します。
floatingLabelDirectionプロパティの設定できる値は次のとおりで、既定値はFloatingLabelDirection.Outsideです。
FloatingLabelDirectionの値
説明
Outside
入力中にラベルが外側に表示する
ThroughBorder
入力中にラベルが上の線と重なって表示する
Inside
入力中にラベルが内側に表示する
また、floatingLabelTypeプロパティを設定すると、入力中のフローティングラベルの表示位置を設定できます。floatingLabelTypeプロパティの設定できる値は次のとおりで、既定値はFloatingLabelType.Autoです。
FloatingLabelTypeの値
説明
Auto
入力中にラベルがfloatingLabelDirectionに設定した位置に調整される
Always
ラベルが常に表示する
None
ラベルが常に表示しない
注意事項
watermarkDisplayNullTextプロパティと同時に設定すると、フローティングラベルがウォーターマークと重なる場合もあります。
<template>
<div>
<div>
<GcTagBoxComponent
width="300"
:items="products"
floatingLabelText="商品"
:floatingLabelDirection="floatingLabelDirection"
:floatingLabelType="floatingLabelType"
/>
</div>
<br/>
<div>
フローティングラベルのスタイルを変更する<br/>
<div class="custom">
<GcTagBoxComponent
width="300"
:items="products"
floatingLabelText="商品"
:floatingLabelDirection="floatingLabelDirection"
:floatingLabelType="floatingLabelType"
/>
</div>
</div>
<table class="sample">
<tbody>
<tr>
<th>入力中のラベルの表示位置</th>
<td>
<select v-model="floatingLabelDirection">
<option value="outside">外側</option>
<option value="throughborder" selected>上線と重なる</option>
<option value="inside">内側</option>
</select>
</td>
</tr>
<tr>
<th>入力中のラベルの表示</th>
<td>
<select v-model="floatingLabelType">
<option value="auto" selected>設定位置</option>
<option value="always">常に表示</option>
<option value="none">常に表示しない</option>
</select>
</td>
</tr>
</tbody>
</table>
</div>
</template>
<script setup>
import '@mescius/inputman/CSS/gc.inputman-js.css';
import { ref } from 'vue';
import '@mescius/inputman.vue';
import { GcTagBoxComponent } from '@mescius/inputman.vue';
import { InputMan } from "@mescius/inputman";
import { products } from './data.js';
import './styles.css';
InputMan.appearanceStyle = InputMan.AppearanceStyle.Modern;
const floatingLabelDirection = ref(InputMan.FloatingLabelDirection.ThroughBorder);
const floatingLabelType = ref(InputMan.FloatingLabelType.Auto);
</script>
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>タグボックスコントロール - フローティングラベルの表示</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<script src="node_modules/systemjs/dist/system.src.js"></script>
<script src="systemjs.config.js"></script>
<script src="compiler.js" type="module"></script>
<script>
window.onload = function() {
var System = SystemJS;
System.import("./src/app.js");
}
</script>
</head>
<body>
<div id="app"></div>
</body>
</html>
export const products = ['果汁100%オレンジ', '果汁100%グレープ', '果汁100%レモン', '果汁100%ピーチ', 'コーヒーマイルド', 'コーヒービター'];
body {
padding-bottom: 10rem;
}
.custom .gcim {
border-color: rgb(255, 204, 127);
}
.custom .gcim_focused {
border-color: rgb(255, 127, 127);
}
.custom .gcim-floating-label__container[label-state='floating'][label-direction='throughborder'] {
font-family: 'Serif';
font-size: medium;
color: rgb(255, 127, 127);
left: 30px;
}
.custom .gcim-floating-label__container[label-state='floating'][label-direction='throughborder'] {
color: rgb(255, 204, 127);
}
.custom .gcim_focused .gcim-floating-label__container[label-state='floating'][label-direction='throughborder'] {
color: rgb(255, 127, 127);
}
.custom .gcim-floating-label__container[label-state='display'] {
font-family: 'Serif';
font-size: medium;
color: rgb(255, 204, 127);
left: 30px;
}
body {
padding-bottom: 10rem;
}
[gcim-control-appearance="modern"] .custom .gcim {
border-color: rgb(255, 204, 127);
}
[gcim-control-appearance="modern"] .custom .gcim_focused {
border-color: rgb(255, 127, 127);
}
[gcim-control-appearance="modern"] .custom .gcim-floating-label__container[label-state='floating'][label-direction='throughborder'] {
font-family: 'Serif';
font-size: medium;
color: rgb(255, 127, 127);
left: 30px;
}
[gcim-control-appearance="modern"] .custom .gcim-floating-label__container[label-state='floating'][label-direction='throughborder'] {
color: rgb(255, 204, 127);
}
[gcim-control-appearance="modern"] .custom .gcim_focused .gcim-floating-label__container[label-state='floating'][label-direction='throughborder'] {
color: rgb(255, 127, 127);
}
[gcim-control-appearance="modern"] .custom .gcim-floating-label__container[label-state='display'] {
font-family: 'Serif';
font-size: medium;
color: rgb(255, 204, 127);
left: 30px;
}
(function (global) {
SystemJS.config({
transpiler: 'plugin-babel',
babelOptions: {
es2015: true
},
paths: {
// paths serve as alias
'npm:': 'node_modules/'
},
packageConfigPaths: [
'./node_modules/*/package.json',
"./node_modules/@mescius/*/package.json",
"./node_modules/@babel/*/package.json",
"./node_modules/@vue/*/package.json"
],
map: {
'vue': "npm:vue/dist/vue.esm-browser.js",
'plugin-babel': 'npm:systemjs-plugin-babel/plugin-babel.js',
"systemjs-babel-build": "npm:systemjs-plugin-babel/systemjs-babel-browser.js",
"@mescius/inputman": 'npm:@mescius/inputman/index.js',
"@mescius/inputman.vue": 'npm:@mescius/inputman.vue/lib/gc.inputman.plugin.vue.js',
"@mescius/inputman/CSS": "npm:@mescius/inputman/CSS",
"@mescius/inputman.richtexteditor": "npm:@mescius/inputman.richtexteditor/index.js",
"@mescius/inputman.richtexteditor.vue": "npm:/@mescius/inputman.richtexteditor.vue/lib/gc.inputman.richtexteditor.plugin.vue.js",
"@mescius/inputman.richtexteditor/CSS": "npm:@mescius/inputman.richtexteditor/CSS",
'@mescius/wijmo': 'npm:@mescius/wijmo/index.js',
'@mescius/wijmo.styles': 'npm:@mescius/wijmo.styles',
'@mescius/wijmo.cultures': 'npm:@mescius/wijmo.cultures/wijmo.culture.ja.js',
'@mescius/wijmo.nav': 'npm:@mescius/wijmo.nav/index.js',
'@mescius/wijmo.input': 'npm:@mescius/wijmo.input/index.js',
'@mescius/wijmo.grid': 'npm:@mescius/wijmo.grid/index.js',
'@mescius/spread-sheets': 'npm:@mescius/spread-sheets/index.js',
'@mescius/spread-sheets-resources-ja': 'npm:@mescius/spread-sheets-resources-ja/index.js',
'@mescius/spread-sheets/styles': 'npm:@mescius/spread-sheets/styles',
'css': 'npm:systemjs-plugin-css/css.js',
},
meta: {
'*.css': { loader: 'css' },
'*.vue': { loader: "../plugin-vue/index.js" }
}
});
})(this);