LocaleSelect

A simple language switcher as a select.

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-locale-select component provides a language switcher based on a Monster select control. It detects available languages, filters out the current one, and navigates to the selected locale URL.

Selection Behavior

When a user selects a language, the component redirects the browser to the selected locale. If features.resetCookie is enabled, it clears the configured cookie before redirecting.

Labels

Use labels["select-an-option"] to override the placeholder label displayed in the select control.

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

HTML

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

Stylesheet

/** no additional stylesheet is defined **/

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.