LocaleSelect

A select-based locale switcher for multilingual forms, apps and documentation surfaces.

Import
the javascript logo
import { LocaleSelect } from "@schukai/monster/source/components/accessibility/locale-select.mjs";
Source
the git logo
Package
Since
3.97.0

Introduction

The Monster LocaleSelect offers language switching through a select-based control. Use it when locale choice should fit naturally into forms, settings areas or compact toolbars.

When to use LocaleSelect

  • Use it when a select fits the surrounding UI: Settings forms and compact headers are common cases.
  • Use it for predictable locale lists: A select works well when the available languages are explicit.
  • Do not use it when a more prominent language switcher is needed: Public-facing language choice may deserve a stronger affordance.

Simple Language Switcher

A simple locale selector that redirects to the chosen language. The reset-cookie feature is disabled for this example.

Javascript

import '@schukai/monster/source/components/accessibility/locale-select.mjs';

const selector = document.createElement('monster-locale-select');
selector.setOption('labels.select-an-option', 'Select a language');
selector.setOption('features.resetCookie', false);

document.body.appendChild(selector);<script type="module">import '@schukai/monster/source/components/accessibility/locale-select.mjs';

const selector = document.createElement('monster-locale-select');
selector.setOption('labels.select-an-option', 'Select a language');
selector.setOption('features.resetCookie', false);

document.getElementById('locale-select-simple').appendChild(selector);</script>

HTML

<div id="locale-select-simple"></div>

Stylesheet

/** no additional stylesheet is defined **/
Open in playground

Runtime Locale Configuration

Builds the locale list from real language links and updates the public label option at runtime.

Javascript

import "@schukai/monster/source/components/accessibility/locale-select.mjs";

await customElements.whenDefined("monster-locale-select");

const selector = document.getElementById("locale-runtime");
selector.setOption("features.resetCookie", false);

document.getElementById("locale-runtime-label").addEventListener("click", () => {
  selector.setOption("labels.select-an-option", "Language");
});

HTML

<section style="display:grid;gap:var(--monster-space-3)">
  <nav aria-label="Available languages">
    <a href="?lang=en" lang="en">English</a>
    <a href="?lang=de" lang="de">Deutsch</a>
    <a href="?lang=fr" lang="fr">Français</a>
  </nav>
  <monster-locale-select id="locale-runtime"></monster-locale-select>
  <button id="locale-runtime-label" type="button">Use compact label</button>
</section>

Stylesheet

/** no additional stylesheet is defined **/
Open in playground

Component Design

The locale select wraps monster-select and exports its parts to keep styling flexible. Use ::part() to align the control with your layout and theme.

Exported Parts

All standard select parts are exported, including control, popper, and selection.


monster-locale-select::part(control) {
    min-width: 220px;
}

monster-locale-select::part(selection) {
    padding: 0.2rem 0.4rem;
}

Customizing With Parts

You can adapt the visual appearance through exported parts instead of modifying the internal template. This reference is generated from the current component source.

The component exposes these part names:

  • badge: Element representing the badge.
  • badge-label: Element representing the badge label.
  • container: Primary internal layout container.
  • content: Main content region.
  • control: Outer wrapper of the component.
  • inline-filter: Element representing the inline filter.
  • no-options: Element representing the no options.
  • option: Element representing the option.
  • option-control: Element representing the option control.
  • option-label: Element representing the option label.
  • popper: Floating popper container.
  • popper-filter: Element representing the popper filter.
  • remote-info: Element representing the remote info.
  • remove-badge: Element representing the remove badge.
  • selection: Element representing the selection.
  • status-or-remove-badges: Element representing the status or remove badges.
  • summary: Summary region.

HTML Structure

<monster-locale-select></monster-locale-select>

JavaScript Initialization

const element = document.createElement('monster-locale-select');
document.body.appendChild(element);

Exported

LocalSelector

Derived from

CustomElement

Options

The Options listed in this section are defined directly within the class. This class is derived from several parent classes, including the CustomElement class. Therefore, it inherits Options from these parent classes. If you cannot find a specific Options in this list, we recommend consulting the documentation of the CustomElement.

Option
Type
Default
Description
-/-

  • since
  • deprecated

Properties and Attributes

The Properties and Attributes listed in this section are defined directly within the class. This class is derived from several parent classes, including the CustomElement class and ultimately from HTMLElement. Therefore, it inherits Properties and Attributes from these parent classes. If you cannot find a specific Properties and Attributes in this list, we recommend consulting the documentation of the CustomElement.

  • data-monster-options: Sets the configuration options for the collapse component when used as an HTML attribute.
  • data-monster-option-[name]: Sets the value of the configuration option [name] for the collapse component when used as an HTML attribute.

Methods

The methods listed in this section are defined directly within the class. This class is derived from several parent classes, including the CustomElement class and ultimately from HTMLElement. Therefore, it inherits methods from these parent classes. If you cannot find a specific method in this list, we recommend consulting the documentation of the CustomElement.

Static methods

[instanceSymbol]()
Returns
  • {symbol}
Used by the instanceof operator.
exportparts()
Export parts from monster-select to make them available for styling outside.
getCSSStyleSheet()
Returns
  • {CSSStyleSheet[]}
No description available.
getTag()
Returns
  • {string}
No description available.

Lifecycle methods

Lifecycle methods are called by the environment and are usually not intended to be called directly.

[assembleMethodSymbol]()
Returns
  • {LocaleSelect}
Initializes the component.
connectedCallback()
connectedCallback

Events

This component does not fire any public events. It may fire events that are inherited from its parent classes.

The current width of the area is too small to display the content correctly.