Skip to content

Commit 1909b36

Browse files
madsrasmusseniOvergaard
authored andcommitted
feat: implement readonly for uui-combobox
1 parent f1978e0 commit 1909b36

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

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

+17-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import {
77
} from '@umbraco-ui/uui-combobox-list/lib';
88
import { iconRemove } from '@umbraco-ui/uui-icon-registry-essential/lib/svgs';
99
import type { UUIPopoverContainerElement } from '@umbraco-ui/uui-popover-container/lib';
10-
import { css, html, LitElement } from 'lit';
10+
import { css, html, LitElement, nothing } from 'lit';
1111
import {
1212
property,
1313
query,
@@ -103,6 +103,15 @@ export class UUIComboboxElement extends UUIFormControlMixin(LitElement, '') {
103103
@property({ type: Boolean, reflect: true })
104104
disabled = false;
105105

106+
/**
107+
* Sets the input to readonly mode, meaning value cannot be changed but still able to read and select its content.
108+
* @type {boolean}
109+
* @attr
110+
* @default false
111+
*/
112+
@property({ type: Boolean, reflect: true })
113+
readonly = false;
114+
106115
@query('#combobox-input')
107116
private _input!: HTMLInputElement;
108117

@@ -239,11 +248,13 @@ export class UUIComboboxElement extends UUIFormControlMixin(LitElement, '') {
239248
};
240249

241250
#onToggle = () => {
251+
if (this.readonly) return;
242252
this.open = !this.open;
243253
};
244254

245255
#onOpen = () => {
246256
if (this.open) return;
257+
if (this.readonly) return;
247258
this.open = true;
248259
};
249260

@@ -298,12 +309,13 @@ export class UUIComboboxElement extends UUIFormControlMixin(LitElement, '') {
298309
.value=${this._displayValue}
299310
autocomplete="off"
300311
.disabled=${this.disabled}
312+
.readonly=${this.readonly}
301313
popovertarget="combobox-popover"
302314
@click=${this.#onToggle}
303315
@input=${this.#onInput}
304316
@keydown=${this.#onKeyDown}>
305317
<slot name="input-prepend" slot="prepend"></slot>
306-
${this.disabled ? '' : this.#renderClearButton()}
318+
${this.#renderClearButton()}
307319
<div id="expand-symbol-wrapper" slot="append">
308320
<uui-symbol-expand .open=${this._isOpen}></uui-symbol-expand>
309321
</div>
@@ -312,6 +324,9 @@ export class UUIComboboxElement extends UUIFormControlMixin(LitElement, '') {
312324
};
313325

314326
#renderClearButton = () => {
327+
if (this.disabled) return nothing;
328+
if (this.readonly) return nothing;
329+
315330
return this.value || this.search
316331
? html`<uui-button
317332
id="clear-button"

0 commit comments

Comments
 (0)