<vega-input-select
id ="my-select"
required=false
placeholder="placeholder text"
max-height="400"
select-type="single"
auto-validation="true">
</vega-input-select>
const vegaInputSelect = document.getElementById("my-select");
vegaInputSelect.source = [
{id: "id1", displayName: "name1"},
{id: "id2", displayName: "name2"},
{id: "id3", displayName: "name3"},
{id: "id4", displayName: "name4"},
];<vega-input-select
id ="my-select"
size="small"
required=false
placeholder="placeholder text"
max-height="400"
auto-validation="true">
</vega-input-select>
const vegaInputSelect = document.getElementById("my-select");
vegaInputSelect.source = [
{id: "id1", displayName: "name1"},
{id: "id2", displayName: "name2"},
{id: "id3", displayName: "name3"},
{id: "id4", displayName: "name4"},
];<vega-input-select
id ="my-select"
required=false
placeholder="placeholder text"
max-height="400"
select-type="multiple"
auto-validation="true">
</vega-input-select>
const vegaInputSelect = document.getElementById("my-select");
vegaInputSelect.source = [
{id: "id1", displayName: "name1"},
{id: "id2", displayName: "name2"},
{id: "id3", displayName: "name3"},
{id: "id4", displayName: "name4"},
];Note: The above example uses Vanilla JS. If you would like to use React, Angular, or Vue, please consult Storybook.
The vega-input-select element is an option select box. It allows choosing an item from a list. It is usually used when there is a long list of entries where a single selection must be made.
The vega-input-select element also allows typing in the name of the selection which uses autocomplete to fill the input field.
Note: Populating values into vega-input-select requires inputting them into a JavaScript array.
| Name | Description | Default |
|---|---|---|
| size | The size of the input select. ResponsiveType: default, small |
default |
| required | Indicates whether or not the input select is required. boolean | false |
| label | Sets the default label text for the select. string | "" |
| max-height | Sets the maximum height for the drop-down. number | 400 |
| form-validation | Updating the value of this property triggers the validation process. | - |
| value | The value of this select field. | - |
| source | The data source of the options | [] |
| disabled | A Boolean indicating if the input field is disabled. boolean | false |
| placeholder | A placeholder string indicating the input format. string | |
| auto-validation | Boolean indicator for whether to automatically validate the user’s input. | true |
| position-relative-to | This is the selector of the element that will contain the popup. If not provided, the popup will be appended to the body. If you encounter the problem of scrolling positioning, try to modify this property. string | |
| prefix-icon | This attribute will preset an icon. Acceptable values are listed under the vega-icon design token. You may alternately use a Font Awesome class for this icon. | |
| hint | A hint message.string |
|
| vega-dropdown-props | Partial properties for vega-dropdown components. Includes positionRelativeTo maxHeight matchContainerHeight searchable caseSensitive matchTargetWidth |
{ maxHeight: 400, matchContainerHeight: false, searchable: true, caseSensitive: false, } |
| selected-label | Allows setting of a custom label for selected items. Use only when select-type is set to multiple. current value will be transferred back to this component as a callback. (value: string[]) => string |
(value) => ${value.length} Selected |
| selected-label | Changes the mode of the select to be single or multiple. single multiple |
single |
| validation-rules | The array custom validation rule for attaching to the input takes the following format: Array<{canEvaluate: (input: string) => boolean, evaluate: (input: string) => EvaluateResult}> |
<vega-input-select
required=true|false
label={label}
max-height={maximum height}
data-id=xxx
data-label=xxx
form-validation=0
value=xxx
position-relative-to="#{id} | .{class} ..."
selected-label="(value: string[]) => '{value.length} of 4 Selected'"
>
</vega-input-select>
Adding options to vega-select requires providing them through an array. For example:
const vegaInputSelect = document.getElementById('my-select');
vegaInputSelect.source = [
{ id: 'id1', displayName: 'name1' },
{ id: 'id2', displayName: 'name2' },
{ id: 'id3', displayName: 'name3' },
];
The validation for vega-input-select is automatically triggered either through the search input event or through blur. In addition, you can also call the valid() method to trigger validation manually.
valid() method. Note: due to StencilJS requirements, the valid() method returns a promise object. To get the fulfilled value of this promise object, use the await operator. These values are boolean; a result of true indicates validity.document.getElementById('submit-btn').addEventListener('click', async () => {
const vegaInputSelect = document.getElementById('id-for-vega-input-select');
if (await vegaInputSelect.valid()) {
// valid
} else {
// invalid
}
});
The value property in vega-input-select behaves the same as the value attribute in standard HTML. You may access it in the same way:
<vega-input-select id="select-id" value="CA" ></vega-input>
<script>
const value = document.getElementById("select-id").value
</script>
The following events are dispatched as part of vega-input-select.
vega-input-select is changed.document.getElementById("select_id").addEventListener("vegaChange", (e) => {
console.log(e.currentTarget.value) })
vega-input-select is changed.document.getElementById("select_id").addEventListener("vegaValidate", (e) => {
console.log(e.currentTarget.isValid) })
The following methods are available for vega-input-select.
doOpen opens the select dropdown.doClose closes the select dropdown and closes the element ref. doChange will change the selected id.
<vega-input-select id="vega-input-select"></vega-input-select>;
// display dropdown
document.querySelector('#vega-input-select').doOpen();
// hide dropdown
document.querySelector('#vega-input-select').doClose();
// change selected id
document.querySelector('#vega-input-select').doChange('id-of-source-item');
For more details, view in Storybook.
aria-describedby attributes.vega-radio element may work better. Do
Don't