Skip to content

Commit 0180ee2

Browse files
JesmoDevJesper Møller JenseniOvergaard
authored
fix(uui-combobox): fix for small resolutions (#327)
* added phone overlay with media query * make it more readable on phone * phone wrapper is now fixed so it works inside form layouts * add property to hold the close button text Co-authored-by: Jesper Møller Jensen <[email protected]> Co-authored-by: Jacob Overgaard <[email protected]>
1 parent 8c6775b commit 0180ee2

File tree

1 file changed

+67
-9
lines changed

1 file changed

+67
-9
lines changed

packages/uui-combobox/lib/uui-combobox.element.ts

Lines changed: 67 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ export class UUIComboboxElement extends FormControlMixin(LitElement) {
3030
static styles = [
3131
css`
3232
:host {
33-
position: relative;
3433
display: inline-block;
3534
}
3635
@@ -40,8 +39,9 @@ export class UUIComboboxElement extends FormControlMixin(LitElement) {
4039
}
4140
4241
#scroll-container {
43-
max-height: var(--uui-combobox-popover-max-height, 500px);
4442
overflow-y: auto;
43+
width: 100%;
44+
max-height: var(--uui-combobox-popover-max-height, 500px);
4545
}
4646
4747
#dropdown {
@@ -66,6 +66,32 @@ export class UUIComboboxElement extends FormControlMixin(LitElement) {
6666
flex-shrink: 0;
6767
margin-top: -1px;
6868
}
69+
70+
#phone-wrapper {
71+
position: fixed;
72+
inset: 0;
73+
display: flex;
74+
flex-direction: column;
75+
z-index: 1;
76+
font-size: 1.1em;
77+
}
78+
79+
#phone-wrapper #dropdown {
80+
display: flex;
81+
}
82+
83+
#phone-wrapper #combobox-input {
84+
height: var(--uui-size-16);
85+
}
86+
87+
#phone-wrapper > uui-button {
88+
height: var(--uui-size-14);
89+
width: 100%;
90+
}
91+
92+
#phone-wrapper #scroll-container {
93+
max-height: unset;
94+
}
6995
`,
7096
];
7197

@@ -106,6 +132,15 @@ export class UUIComboboxElement extends FormControlMixin(LitElement) {
106132
@property({ type: Boolean })
107133
public open = false;
108134

135+
/**
136+
* Specifies the button label for the close button in mobile mode
137+
* @type { string }
138+
* @attr
139+
* @default "Close"
140+
*/
141+
@property({ type: String })
142+
public closeLabel = 'Close';
143+
109144
@query('#combobox-input')
110145
private _input!: HTMLInputElement;
111146

@@ -116,18 +151,27 @@ export class UUIComboboxElement extends FormControlMixin(LitElement) {
116151
private _comboboxListElements?: UUIComboboxListElement[];
117152

118153
private _comboboxList!: UUIComboboxListElement;
154+
private phoneMediaQuery!: MediaQueryList;
155+
119156
@state()
120157
private _displayValue = '';
121158

122159
@state()
123160
private _search = '';
124161

162+
@state()
163+
private _isPhone = false;
164+
125165
connectedCallback(): void {
126166
super.connectedCallback();
127167

128168
this.addEventListener('blur', this._onBlur);
129169
this.addEventListener('mousedown', this._onMouseDown);
130170

171+
this.phoneMediaQuery = window.matchMedia('(max-width: 600px)');
172+
this._onPhoneChange();
173+
this.phoneMediaQuery.addEventListener('change', this._onPhoneChange);
174+
131175
demandCustomElement(this, 'uui-icon');
132176
demandCustomElement(this, 'uui-input');
133177
demandCustomElement(this, 'uui-button');
@@ -141,6 +185,7 @@ export class UUIComboboxElement extends FormControlMixin(LitElement) {
141185

142186
this.removeEventListener('blur', this._onBlur);
143187
this.removeEventListener('mousedown', this._onMouseDown);
188+
this.phoneMediaQuery.removeEventListener('change', this._onPhoneChange);
144189
}
145190

146191
protected async firstUpdated() {
@@ -161,6 +206,10 @@ export class UUIComboboxElement extends FormControlMixin(LitElement) {
161206
}
162207
}
163208

209+
private _onPhoneChange = () => {
210+
this._isPhone = this.phoneMediaQuery.matches;
211+
};
212+
164213
private _updateValue(value: string) {
165214
if (this._comboboxList) {
166215
this._comboboxList.value = value;
@@ -295,14 +344,23 @@ export class UUIComboboxElement extends FormControlMixin(LitElement) {
295344
};
296345

297346
render() {
298-
return html`
299-
<uui-popover
300-
.open=${this.open}
301-
.margin=${-1}
302-
@close=${() => this._onClose()}>
347+
if (this._isPhone && this.open) {
348+
return html` <div id="phone-wrapper">
349+
<uui-button label="close" look="primary" @click=${this._onClose}>
350+
${this.closeLabel}
351+
</uui-button>
303352
${this._renderInput()} ${this._renderDropdown()}
304-
</uui-popover>
305-
`;
353+
</div>`;
354+
} else {
355+
return html`
356+
<uui-popover
357+
.open=${this.open}
358+
.margin=${-1}
359+
@close=${() => this._onClose()}>
360+
${this._renderInput()} ${this._renderDropdown()}
361+
</uui-popover>
362+
`;
363+
}
306364
}
307365
}
308366

0 commit comments

Comments
 (0)