Skip to content

Commit bca032c

Browse files
committed
Allow the listbox width to be customized by CSS var
1 parent 9b8afc7 commit bca032c

File tree

2 files changed

+15
-7
lines changed

2 files changed

+15
-7
lines changed

src/labs/ia-combo-box/ia-combo-box-story.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -343,11 +343,6 @@ export class IAComboBoxStory extends LitElement {
343343

344344
static get styles(): CSSResultGroup {
345345
return css`
346-
ia-combo-box::part(combo-box) {
347-
border: 1px solid #404040;
348-
border-radius: 0px;
349-
}
350-
351346
#announcer {
352347
margin-top: 10px;
353348
}

src/labs/ia-combo-box/ia-combo-box.ts

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -851,14 +851,17 @@ export class IAComboBox extends LitElement {
851851

852852
openOptionsMenu(): void {
853853
this.open = true;
854+
this.emitToggleEvent();
854855
}
855856

856857
closeOptionsMenu(): void {
857858
this.open = false;
859+
this.emitToggleEvent();
858860
}
859861

860862
toggleOptionsMenu(): void {
861863
this.open = !this.open;
864+
this.emitToggleEvent();
862865
}
863866

864867
private updateFormValidity(): void {
@@ -881,6 +884,14 @@ export class IAComboBox extends LitElement {
881884
);
882885
}
883886

887+
private emitToggleEvent(): void {
888+
this.dispatchEvent(
889+
new CustomEvent<boolean>('toggle', {
890+
detail: this.open,
891+
}),
892+
);
893+
}
894+
884895
//
885896
// HELPERS
886897
//
@@ -904,7 +915,7 @@ export class IAComboBox extends LitElement {
904915
const optionsListStyles: Record<string, string> = {
905916
top: `${mainWidgetRect.bottom + scrollY}px`,
906917
left: `${mainWidgetRect.left + scrollX}px`,
907-
width: `${mainWidgetRect.width}px`,
918+
width: `var(--comboBoxListWidth, ${mainWidgetRect.width}px)`,
908919
maxHeight: `min(${usableHeightBelow}px, ${maxHeightVar})`,
909920
};
910921

@@ -1039,7 +1050,7 @@ export class IAComboBox extends LitElement {
10391050
/**
10401051
* The IAComboBoxOption that is currently selected, or null if none is selected.
10411052
*/
1042-
private get selectedOption(): IAComboBoxOption | null {
1053+
get selectedOption(): IAComboBoxOption | null {
10431054
if (this.value == null) return null;
10441055
return this.getOptionFor(this.value);
10451056
}
@@ -1074,6 +1085,7 @@ export class IAComboBox extends LitElement {
10741085
align-items: stretch;
10751086
flex-wrap: nowrap;
10761087
background: white;
1088+
border: 1px solid black;
10771089
}
10781090
10791091
.focused #main-widget-row {
@@ -1086,6 +1098,7 @@ export class IAComboBox extends LitElement {
10861098
background: transparent;
10871099
border: none;
10881100
padding: var(--comboBoxPadding, 5px);
1101+
width: 100%;
10891102
font-size: inherit;
10901103
outline: none;
10911104
}

0 commit comments

Comments
 (0)