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
the npm logo
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

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;
}

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]()
Used by the instanceof operator.
exportparts()
Export parts from monster-select to make them available for styling outside.
getCSSStyleSheet()
Returns
  • {CSSStyleSheet[]}
getTag()
Returns
  • {string}

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.