Provides single select, multiselect, and searchability with consistent visual presentation and interactions. It also supports pseudo search when a key is pressed on focus state.
Oftentimes, displaying more than a single line of text may become necessary to help a user make a selection. That is why, within the q2-select
component, there is the ability to provide robust content for each option. This feature allows you to override the default appearance by providing custom markup to display to the user within your q2-option
components.
While this may be any standard HTML you would like, we strongly suggest using the q2-item
component as it is built with several design patterns in mind.
<q2-select label="Account" multiline-options value="2">
<q2-option value="1">
<q2-item>
<div slot="header">Checking Account</div>
<q2-detail label="Account Number" description="xxxx-2376" slot="body">
<q2-currency amount="12953.25"></q2-currency>
</q2-detail>
<q2-detail label="Current Balance" slot="body">
<q2-currency amount="12953.25"></q2-currency>
</q2-detail>
</q2-item>
</q2-option>
<q2-option value="2">
<q2-item>
<div slot="header">Savings Account</div>
<q2-detail label="Account Number" description="xxxx-4595" slot="body"></q2-detail>
<q2-detail label="Current Balance" slot="body">
<q2-currency amount="95321.16"></q2-currency>
</q2-detail>
</q2-item>
</q2-option>
<q2-option value="3">
<q2-item>
<div slot="header">Secret Account</div>
<q2-detail label="Account Number" description="xxxx-8129" slot="body"></q2-detail>
<q2-detail label="Current Balance" slot="body">
<q2-currency amount="8451.13"></q2-currency>
</q2-detail>
</q2-item>
</q2-option>
</q2-select>
Once you make a selection, the content of the selected option will be displayed in the input field. If there are elements within the robust content that you would like to hide in the selected view, you can use the hide-on-select
attribute to hide them.
The minimum and maximum height of the q2-select
component can be modified by customizing the following CSS variables:
--tct-input-min-height
- The minimum height of the input field. Defaults to 44px
.--tct-input-max-height
- The maximum height of the input field. Defaults to none
.If you do not want the robust content to be displayed in the selected state, you can use the display
attribute on the q2-option
component, which will tell the q2-select
component that you want that text to display instead of the robust content.
<q2-select label="Account" multiline-options value="2">
<q2-option value="1" display="Checking account xxxx-2376">
<q2-item>
<div slot="header">Checking Account</div>
<q2-detail label="Account Number" description="xxxx-2376" slot="body">
<q2-currency amount="12953.25"></q2-currency>
</q2-detail>
<q2-detail label="Current Balance" slot="body">
<q2-currency amount="12953.25"></q2-currency>
</q2-detail>
</q2-item>
</q2-option>
<q2-option value="2" display="Savings account XXXX-4595">
<q2-item>
<div slot="header">Savings Account</div>
<q2-detail label="Account Number" description="xxxx-4595" slot="body"></q2-detail>
<q2-detail label="Current Balance" slot="body">
<q2-currency amount="95321.16"></q2-currency>
</q2-detail>
</q2-item>
</q2-option>
<q2-option value="3" display="Secret account xxxx-8129">
<q2-item>
<div slot="header">Secret Account</div>
<q2-detail label="Account Number" description="xxxx-8129" slot="body"></q2-detail>
<q2-detail label="Current Balance" slot="body">
<q2-currency amount="8451.13"></q2-currency>
</q2-detail>
</q2-item>
</q2-option>
</q2-select>
By default, if a q2-select
element has the searchable
attribute, it will search through the provided options and display any found results. You can, however, provide a custom search function as well.
Example HTML
<q2-select label="Field label" searchable oninput="customFilterExample(event)">
<q2-option value="1" display="Option 1">Option 1</q2-option>
<q2-option value="2" display="Option 2">Option 2</q2-option>
<q2-option value="3" display="Option 3" disabled>Option 3</q2-option>
<q2-option value="4" display="Option 4">Option 4</q2-option>
</q2-select>
Example JS
function customFilterExample(event) {
var query = event.detail.query.trim().toLowerCase();
var optionsArr = Array.prototype.slice.call(this.querySelectorAll('q2-option'));
optionsArr.forEach(function(option) {
if (query === '') {
option.style.display = '';
} else {
var display = option.display.toLowerCase();
var innerText = option.innerText.toLowerCase();
var visible = display.includes(query) || innerText.includes(query);
option.style.display = visible ? '' : 'none';
}
});
}
The popover in q2-select
provides slots for custom content to be displayed persistently at the top and/or bottom of the popover menu.
Slot names:
Example HTML
<q2-select label="Select with Popover Slots">
<q2-option value="1" display="Option 1">Option 1</q2-option>
<q2-option value="2" display="Option 2">Option 2</q2-option>
<q2-option value="3" display="Option 3">Option 3</q2-option>
<q2-option value="4" display="Option 4">Option 4</q2-option>
<q2-card slot='popover-top' avatar-icon="person-add" title="Add New User" description='Top Slot Content' type='clickable' is-small style='--tct-card-box-shadow: none'></q2-card>
<div slot='popover-bottom' style='width: 100%; height: 40px;text-align: center; font-size: larger;'>Bottom Slot Content</div>
</q2-select>
The popover slots are not compatible when the hoist
attribute is being used with q2-select
.
The q2-select
element has multiple slots that can be used to insert custom content into the component.
An optional slot to display custom content persistently at the bottom of the popover. This is not compatible with the action sheet workflow.
An optional slot to display custom content persistently at the top of the popover. This is not compatible with the action sheet workflow.
An optional slot to display custom HTML content in the display area.
The q2-select
element has one or more properties that support text localization. Those properties are indicated by the localizable badge in the description.
clearable
Renders an icon button when the field is non-empty. Pressing the button clears all input from the field.
disabled
Disables all interaction with the field and leverages the disabled visual style of q2-input
.
errors
The presence of errors
will mark the field as invalid, putting it into an error state.
hideLabel
hide-label
Hide's the field's <label>
element from view.
Only use when a visible label is impractical.
hoist
Instructs the component to use the action sheet workflow for displaying its options.
For more information, see Action Sheets.
If your q2-select
renders inside of an iframe, and you are using multiline/robust content options,
any custom CSS you apply to your options will not get passed up to the platform which displays the action sheet.
For this reason, we strongly suggest using the q2-card component since its styling is managed by Tecton.
invalid
Determines whether to show an error state. Its primary use-case is for an unfilled field.
label
The text that will be used as the label for the field.
listLabel
list-label
Determines the label that is applied to the option list for accessibility purposes.
minRows
min-rows
The minimum number of rows the component will try to display below or above the component when opened.
multilineOptions
multiline-options
Enables text wrapping for q2-option
elements. When false
, the text truncates and does not wrap.
multiple
Enables multi-select functionality.
optional
Appends "(optional)" to the field label, and sets aria-required
on the nested input tag to false
.
placeholder
Text that appears within the field when it is blurred and empty. Placeholder text disappears when the user selects an option.
popoverMaxHeight
popover-max-height
Force the maximum height of the popover. This value will be interpreted as pixels. If no value is passed, or the value exceeds available space, the component will auto-detect the maximum height based on available space.
popoverMode
popover-mode
Determines the display mode of the popover.
Providing a value of legacy
instructs the popover to use absolute positioning instead of fixed positioning.
This is a temporary solution to work around styling issues related to using fixed positioning for the popover when nested inside of elements with transform properties. This will be removed once the popover API is available for use.
readonly
Appends "(read only)" to the field label, and field becomes unusable, but remains focusable.
Takes priority over optional
if both are true
.
searchable
Enables search functionality.
selectedOptions
selected-options
Each item in this array should correspond to the value of a q2-option
element.
This property is only relevant for multiple
(i.e., multi-select) implementations.
value
The current value for the select. This should correspond to the value of a nested q2-option element. This property is only relevant for single-select implementations.
The q2-select
element exposes events that can be used to send and receive data from the component based on user interaction.
Emitted when an option is selected or deselected.
When the multi-select is enabled, the value
property will be undefined
and the selectedOptions
property
will contain the selected option values.
{ value: string; selectedOptions: string[]; }
If an event handler is bound to the element using:
onchange
property - The default handler will not fire, and the value must be updated in the custom handler.addEventListener("change")
method - The default handler will fire alongside the custom handler.Emitted when the input value changes.
Requires the searchable
prop to be set to true
.
{ query: string; }
The q2-select
element exposes methods that can be used to perform various actions on the component.
Emulates clicking the <input>
to hide the popover if it is visible.
closePopover() => Promise<void>
Emulates clicking the <input>
to display the popover if it is hidden.
openPopover() => Promise<void>
Emulates focusing the <input>
, entering the provided value, and emitting an input
event.
searchOptions(query: string) => Promise<void>
Only applicable when the input is searchable.
Emulates clicking the <input>
to display the popover and selecting the option(s) with the specified value(s).
If the multi-select is enabled and the closePopover
argument is true
(default), the popover will be closed
after the option(s) are selected.
setValue(values: string | string[], options?: { closePopover?: boolean; }) => Promise<void>
This component uses other components in the Tecton library, including:
q2-popover
q2-option-list
q2-input
click-elsewhere
Other components in the Tecton library use this component, including:
q2-pagination
Added support for top and bottom slots of popover
Initial Release
The Q2-select component is a dropdown selection interface that allows users to choose from a predefined list of options. It provides a space-efficient way to present multiple choices while maintaining a clean, organized interface.
Large Option Sets (5+ items) Use Q2-select when presenting 5 or more options to users. The dropdown format conserves screen real estate while providing easy access to all available choices.
Familiar Categories Ideal for commonly understood option sets such as:
Critical Decisions Avoid for high-stakes choices where users benefit from seeing all options simultaneously to make informed comparisons.
Frequently Changed Settings Not ideal for options that users toggle frequently, as the interaction overhead outweighs the space savings.
Complex Relationships When option dependencies or mutual exclusions are complex, more transparent selection methods may be preferable.
Option Count is High
Options Are Familiar
Space Efficiency is Critical
Option Count is Low
Comparison is Important
Immediate Visibility Required
Use concise, single-line labels when:
Labels Are Self-Explanatory
Options: Checking, Savings, Money Market, CD, IRA Priority: Low, Normal, High, Critical Status: Draft, Review, Approved, Published
Context Provides Clarity When the surrounding interface makes the option meaning clear without additional explanation.
Implement robust, multi-line content when:
Options Require Explanation
`Basic Checking $9/month - Free with a Direct Deposit
Professional Checking
$29/month - Free with a Direct Deposit and a daily average balance of $5000, .05% APR
Gold Checking $99/month - Free Wires, dedicated account manager`
Differentiation is Complex When options have subtle but important differences that affect user decision-making.
Rich Context Improves Outcomes User research indicates that additional information leads to better selections and fewer errors.
The following CSS variables are available to override the default theme styles of the q2-select
component.
Many Tecton components consume other components to maintain visual and functional consistency. If you are looking for a CSS variable you think should exist but are not seeing it, it may be defined in one of the dependent components below. Either way, if you think it's something we should expose more conveniently, let us know!
There is 1 frequently asked question related to this page.