) {
super.updated(changedProperties);
// Handle options changes - need to reinitialize for new option list
if (changedProperties.has('options')) {
this.cleanup?.();
this.cleanup = initializeComboBox(this);
}
}
override disconnectedCallback() {
super.disconnectedCallback();
this.cleanup?.();
}
private renderError() {
if (!this.error) return '';
return html`
Error: ${this.error}
`;
}
private renderRequiredIndicator() {
if (!this.required) return '';
return html`*`;
}
private renderHint() {
if (!this.hint) return '';
return html`${this.hint}
`;
}
private renderLabel(selectId: string) {
// Always provide a label for accessibility
return html`
`;
}
private renderPlaceholderOption() {
if (!this.placeholder) return '';
return html``;
}
private renderSelectOption(option: ComboBoxOption) {
return html`
`;
}
override render() {
const formGroupClasses = [
'usa-form-group',
this.error || this.errorState ? 'usa-form-group--error' : '',
this.required ? 'usa-form-group--required' : '',
]
.filter(Boolean)
.join(' ');
// Ensure we always have a valid, unique ID for the select element
// Using a more robust ID that's less likely to conflict with USWDS internals
const selectId = this.selectId || this.inputId || `uswds-combo-box-${Math.random().toString(36).substr(2, 9)}`;
const ariaDescribedBy = [
this.hint ? `${selectId}-hint` : '',
this.error ? `${selectId}-error` : '',
]
.filter(Boolean)
.join(' ');
// Render simple select structure that USWDS will transform into a combo box
return html`
`;
}
// Public API methods - delegate to USWDS
show() {
// USWDS will handle opening the combo box when user interacts
const selectElement = this.querySelector('.usa-combo-box select') as HTMLSelectElement;
if (selectElement) {
selectElement.focus();
}
}
hide() {
// USWDS will handle closing the combo box
const selectElement = this.querySelector('.usa-combo-box select') as HTMLSelectElement;
if (selectElement) {
selectElement.blur();
}
}
updateOptions() {
console.log('Combo Box: Update options triggered - requesting re-render');
// Trigger re-render to update the select options
this.requestUpdate();
}
}