Skip to main content Sidebar Design tokens Components Layout Style utilities

We’d love to hear from you. Please reach out to us with any questions or inquiries you may have.

You can contact us via e‐mail at placer.coc.reports+contact@gmail.com.

We look forward to hearing from you!

Got it!
Skip to table of contents

The Placer Toolkit alpha has arrived! 🎉
Plenty of changes are coming your way—some big, some breaking, some even nuclear! Beware the changelog…

Bring it on!

    Select

    <pc-select> 0.5.1 experimental

    Selects allow you to choose items from a menu of predefined options.

    <pc-select>
        <pc-option value="option-1">Option 1</pc-option>
        <pc-option value="option-2">Option 2</pc-option>
        <pc-option value="option-3">Option 3</pc-option>
        <pc-option value="option-4">Option 4</pc-option>
        <pc-option value="option-5">Option 5</pc-option>
        <pc-option value="option-6">Option 6</pc-option>
    </pc-select>
    Code Edit

    This component works well with standard <form> elements. Please refer to the form controls page to learn more about form submission and client‐side validation.

    Demos#

    Labels#

    Use the label attribute to give the select an accessible label. For labels that contain HTML, use the label slot instead.

    Edit

    Hints#

    Add a descriptive hint to a select with the hint attribute. For hints that contain HTML, use the hint slot instead.

    Edit

    Placeholders#

    Use the placeholder attribute to add a placeholder.

    Edit

    Clearable#

    Use the clearable attribute to make the select clearable. The clear button only appears when an option is selected.

    Edit

    Filled#

    Add the filled attribute to draw a filled select.

    Edit

    Pill#

    Use the pill attribute to give selects a pill‐shaped look.

    Edit

    Disabled#

    Use the disabled attribute to disable the select.

    Edit

    Multiple options#

    To allow multiple options to be selected, use the multiple attribute. It’s a good practice to use the clearable attribute as well when this option is enabled. To set multiple values at once, set value to a space‐delimited list of values.

    Edit

    Multi‐select options may wrap, causing the select to expand vertically. You can use the max-options-visible attribute to control the maximum number of selected options to show at once.

    Setting initial values#

    Use the value attribute to set the initial selection.

    When using the multiple attribute, the value attribute uses space‐delimited values to select more than one option. Because of this, <pc-option> values cannot contain spaces. If you’re accessing the value property through JavaScript, it will be an array.

    Edit

    Grouping options#

    Use the Divider component to group listbox items visually. You can also use the <small> tag to provide labels, but they won’t be announced by most assistive devices.

    Edit

    Sizes#

    Use the size attribute to change the select’s size.

    Edit

    Placement#

    The preferred placement of the select’s listbox can be set with the placement attribute. The actual position may vary to ensure the panel remains in the viewport.

    Edit

    Prefixes and suffixes#

    Use the prefix and suffix slots to add presentational icons and text. Avoid slotting in interactive elements, such as buttons and links.

    Edit

    Custom tags#

    When multiple options can be selected, you can provide custom tags by passing a function to the getTag property. Your function can return a string of HTML, a Lit template or an HTMLElement. The getTag() function will be called for each option. The first argument is a <pc-option> element and the second argument is the tag’s index (its position in the tag list).

    Remember that custom tags are rendered in a shadow root. To style them, you can use the style attribute in your template or you can add your own parts and target them with the ::part() selector.

    Edit

    Lazy loading options#

    Lazy loading options is very hard to get right. <pc-select> largely follows how a native <select> works.

    Here are the following conditions:

    • If a <pc-select> is created without any options, but is given a value attribute, its value will be "", and then when options are added, if any of the options have a value equal to the <pc-select> value, the value of the <pc-select> will be equal that of the option.

    For example, <pc-select value="foo"> will have a value of "" until <pc-option value="foo">Foo</pc-option> connects, at which point its value will become "foo" when submitting.

    • If a <pc-select multiple> with an initial value has multiple values, but only some of the options are present, it will only respect the options that are present, and if a selected option is loaded in later, and the value of the select has not changed via user interaction or direct property assignment, it will add the selected option ot the form value and to the .value of the select.

    This can be hard to conceptualise, so here’s a fairly large example showing how lazy‐loaded options work with <pc-select> and <pc-select multiple> when given initial value attributes. Feel free to play around with it in this code demo.

    Edit

    Be sure you trust the content you are outputting! Passing unsanitised user input to getTag() can result in XSS vulnerabilities.

    Properties#

    NameDescriptionReflectsDefault
    nameThe name of the select, submitted as a name/value pair with form data.
    Type: string
    ""
    defaultValue
    value
    The default value of the select. Primarily used for resetting the select.
    Type: string | string[]
    ""
    sizeThe select’s size.
    Type: "small" | "medium" | "large"
    "medium"
    placeholderPlaceholder text to show as a hint when the select is empty.
    Type: string
    ""
    multipleAllows more than one option to be selected.
    Type: boolean
    false
    maxOptionsVisible
    max-options-visible
    The maximum number of selected options to show when the multiple attribute is true. After the maximum limit, “+number” will be shown to indicate the number of additional items that are selected. Set the value to 0 to remove the limit.
    Type: number
    3
    disabledDisables the select.
    Type: boolean
    false
    clearableAdds a clear button when the select is not empty.
    Type: boolean
    false
    openIndicates whether or not the select is open. You can toggle this attribute to show and hide the menu, or you can use the show() and hide() methods and this attribute will reflect the select’s open state.
    Type: boolean
    false
    filledDraws a filled select combobox.
    Type: boolean
    false
    pillDraws a pill‐style select.
    Type: boolean
    false
    labelThe select’s label. If you need to display HTML, use the label slot instead.
    Type: string
    ""
    placementThe preferred placement of the select’s listbox. Note that the actual placement may vary to keep the listbox inside of the viewport.
    Type: "top" | "bottom"
    "bottom"
    hintThe select’s hint. If you need to display HTML, use the hint slot instead.
    Type: string
    ""
    formBy default, form controls are associated with the nearest containing <form> element. This attribute allows you to place the form control outside of a form and associate it with the form that has this id. The form must be in the same document or shadow root for this to work.
    Type: string
    ""
    requiredIndicates if the select must be filled in or not.
    Type: boolean
    false
    getTagA function that customises the tags to be rendered when the multiple attribute is true. The first parameter is the option, the second parameter is the current tag’s index. The function should either return either a Lit TemplateResult or a string containing trusted HTML of the symbol to render at the specified value.
    Type: ( option: PcOption, index: number, ) => TemplateResult | string | HTMLElement
    valueThe current value of the select, submitted as a name/value pair with form data. When the multiple attribute is true, the value attribute will be a space‐delimited list of values based on the options selected, and the value property will be an array. For this reason, values must not contain spaces.
    validityGets the validity state object.
    validationMessageGets the validation message.
    updateComplete A read‐only promise that resolves when the component has finished updating.

    Learn more about attributes and properties.

    Slots#

    NameDescription
    (default)The listbox options. Only <pc-option> and <pc-divider> elements can be slotted here. You can use <pc-divider> to group items visually.
    labelThe select’s label. Alternatively, you can use the label attribute.
    prefixUsed to prepend a presentational icon or similar element to the combobox.
    suffixUsed to append a presentational icon or similar element to the combobox.
    clear-iconAn icon to use in place of the default clear icon.
    expand-iconThe icon to show when the select is expanded and collapsed. Rotates on open and close.
    hintText that describes how to use the select. Alternatively, you can use the hint attribute.

    Learn more about using slots.

    Methods#

    NameDescriptionArguments
    show()Shows the listbox.
    hide()Hides the listbox.
    checkValidity()Checks for validity but does not show a validation message. Returns true when valid and false when invalid.
    getForm()Gets the associated form, if one exists.
    reportValidity()Checks for validity and shows the browser’s validation message if the select is invalid.
    setCustomValidity()Sets a custom validation message. Pass an empty string to restore validity.message: string
    focus()Focuses the select.options: FocusOptions
    blur()Unfocuses the select (i.e., blurs it).

    Learn more about methods.

    Events#

    NameDescriptionEvent detail
    pc-inputEmitted when the select receives input.
    pc-changeEmitted when the select’s value changes.
    pc-clearEmitted when the select’s value is cleared.
    pc-focusEmitted when the select gains focus.
    pc-blurEmitted when the select loses focus.
    pc-showEmitted when the select’s menu opens.
    pc-after-showEmitted after the select’s menu opens and all animations are complete.
    pc-hideEmitted when the select’s menu closes.
    pc-after-hideEmitted after the select’s menu closes and all animations are complete.
    pc-invalidEmitted when the select has been checked for validity and its constraints aren’t satisfied.

    Learn more about events.

    Parts#

    NameDescription
    form-controlThe form control that wraps the label, input and hint.
    labelThe select’s label.
    inputThe select’s input.
    hintThe select’s hint.
    comboboxThe container the wraps the prefix, suffix, combobox, clear icon and expand button.
    prefixThe container that wraps the prefix slot.
    suffixThe container that wraps the suffix slot.
    display-inputThe element that displays the selected option’s label, an <input> element.
    listboxThe listbox container where options are slotted.
    tagsThe container that houses option tags when multiselect is used.
    tagThe individual tags that represent each multiselect option.
    tag-baseThe tag’s base part.
    tag-contentThe tag’s content part.
    tag-remove-buttonThe tag’s remove button.
    tag-remove-button-baseThe tag’s remove button base part.
    clear-buttonThe clear button.
    expand-iconThe container that wraps the expand icon.

    Learn more about customising CSS parts.

    Importing#

    If you’re using the autoloader or the standard loader, you can skip this section. But if you’re cherry picking, you can use any of the following snippets to import this component.

    CDN (script tag) CDN (import) npm (import)

    To manually import this component from the CDN, copy this code snippet and paste it in your HTML.

    <script type="module" src="https://cdn.jsdelivr.net/npm/placer-toolkit@1.0.0-alpha.1/cdn/components/select/select.js"></script>

    To manually import this component from the CDN, copy this code snippet and paste it in your JavaScript file.

    import "https://cdn.jsdelivr.net/npm/placer-toolkit@1.0.0-alpha.1/cdn/components/select/select.js";

    To manually import this component from npm, copy this code snippet and paste it in your JavaScript file.

    import "placer-toolkit/dist/components/select/select.js";

    Dependencies#

    This component automatically imports these components: