import { Component, State, Element, h, Prop, Event, Listen, Watch, EventEmitter, AttachInternals } from '@stencil/core';
import { v4 as uuid } from 'uuid';
import { DropdownOption } from './dropdown-option.interface';
import { Dropdown } from './dropdown.interface';
import { HintExpander } from '../ontario-hint-expander/hint-expander.interface';
import { Hint } from '../../utils/common/common.interface';
import { InputCaption } from '../../utils/common/input-caption/input-caption';
import { Caption } from '../../utils/common/input-caption/caption.interface';
import {
validateObjectExists,
validatePropExists,
validateLanguage,
} from '../../utils/validation/validation-functions';
import { ConsoleMessageClass } from '../../utils/console-message/console-message';
import { hasMultipleTrueValues } from '../../utils/helper/utils';
import { getImageAssetSrcPath } from '../../utils/helper/assets';
import { Language } from '../../utils/common/language-types';
import { constructHintTextObject } from '../../utils/components/hints/hints';
import { InputFocusBlurEvent, EventType, InputInteractionEvent } from '../../utils/events/event-handler.interface';
import { handleInputEvent } from '../../utils/events/event-handler';
import { default as translations } from '../../translations/global.i18n.json';
import { ErrorMessage } from '../../utils/components/error-message/error-message';
import { HeaderLanguageToggleEventDetails } from '../../utils/events/common-events.interface';
/**
* Ontario Dropdown List presents a selectable list of predefined options.
*
* This component intentionally does not expose `readOnly` or `disabled` props.
*
* To support accessible and understandable form completion:
* - keep form fields and submission actions available
* - use validation and error messaging to guide corrections
*
* For component guidance, see:
* - https://designsystem.ontario.ca/components/detail/dropdown-lists.html
* - https://designsystem.ontario.ca/developer-docs/components/ontario-dropdown-list/
*
* Disabled/read-only policy source:
* - https://designsystem.ontario.ca/components/detail/buttons.html#disabled-buttons
*/
@Component({
tag: 'ontario-dropdown-list',
styleUrl: 'ontario-dropdown-list.scss',
shadow: true,
formAssociated: true,
assetsDirs: ['./assets'],
})
export class OntarioDropdownList implements Dropdown {
@Element() element: HTMLElement;
@AttachInternals() internals: ElementInternals;
hintTextRef: HTMLOntarioHintTextElement | undefined;
/**
* The text to display for the dropdown list label.
*
* @example
*
*
*/
@Prop() caption: Caption | string;
/**
* The language of the component.
* This is used for translations, and is by default set through event listeners checking for a language property from the header. If no language is passed, it will default to English.
*/
@Prop({ mutable: true }) language?: Language;
/**
* The name for the dropdown list. The name value is used to reference form data after a form is submitted.
*/
@Prop() name: string;
/**
* The ID for the dropdown list.
* If no ID is provided, one will be generated.
*/
@Prop({ mutable: true }) elementId?: string;
/**
* The currently selected dropdown value.
*
* The component keeps the host `value` in sync as users interact with the dropdown.
* If `value` is provided, it takes precedence over any `selected` flags passed through `options`.
*/
@Prop({ mutable: true }) value?: string;
/**
* The options for dropdown list.
*
* Each option will be passed in through an object in the options array.
* This can either be passed in as an object directly (if using react), or as a string in HTML.
*
* In the example below, the options are being passed in as a string and there are three dropdown options displayed.
*
* @example
*
*
*
* As an alternative to `options`, `ontario-dropdown-option` elements can instead be passed as
* light DOM children.
*
* Note: these `` children are read once from the host's light DOM and
* re-rendered as native `