wiki-elements

wiki-language-selector

The wiki-language-selector component allows users to select a language from a list of languages.

Attributes

Events

Examples


                    <wiki-language-selector></wiki-language-selector>
                

Customization

All components under wiki-elements supports Declarative shadow DOM. You can customize the component by adding a template element with shadowrootmode="open" attribute. The template should contain the shadow DOM structure of the component.

To illustrate, the following example shows a customized version of the wiki-language-selector component with a custom header and an button in popover.

                    
                        <wiki-language-selector>
                            <template shadowrootmode="open">
                                <section class="container">
                                     <!-- Add a header, allow more customization by marking it as a slot -->
                                    <slot name="wiki-languageselector-header">
                                        <p>Choose a language - Default header</p>
                                    </slot>
                                    <div class="wrapper" part="wrapper">
                                        <input id="wikilanguageselector-search" type="search" part="input" autocomplete="off" />
                                    </form>
                                </section>
                                <div class="suggestions-popover" popover part="popover">
                                    <p class="suggestions-header">Suggestions</p>
                                    <ul part="suggestions" class="suggestions"></ul>
                                    <!-- Add an actions section at the end of menu -->
                                    <section class="actions">
                                        <button class="example-btn" onclick="clickHander()">Example</button>
                                    </section>
                                </div>
                                <!-- Customize the styles -->
                                <style>
                                    .container {
                                        display: flex;
                                        flex-direction: column;
                                        padding: 1em;
                                        border-bottom: 1px solid CanvasText;
                                        width: 30ch;
                                    }

                                    .suggestions-header {
                                        padding: 0.5em;
                                        font-weight: bold;
                                    }
                                    .actions {
                                        border-top: 1px solid CanvasText;
                                        display: flex;
                                        justify-content: flex-end;
                                        padding: 0.5em;
                                    }
                                </style>
                                <script>
                                    function clickHander() {
                                        alert('Example button clicked');
                                    };
                                </script>
                            </template>
                            <!-- Customize the slot -->
                            <p slot="wiki-langaugeselector-header">Choose a language</p>
                        </wiki-language-selector>
                    
                

And it will render as below:

Choose a language

Additionally, the WikiLanguageSelector class can be extended and methods can be overridden to customize the behavior.