Skip to content

Commit 23c6d2c

Browse files
madsrasmusseniOvergaard
authored andcommitted
feat: add readonly mode
1 parent 7ce49bf commit 23c6d2c

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,15 @@ export class UUISelectElement extends UUIFormControlMixin(LitElement, '') {
6161
@property({ type: Boolean, reflect: true })
6262
disabled = false;
6363

64+
/**
65+
* Sets the input to readonly mode, meaning value cannot be changed but still able to read and select its content.
66+
* @type {boolean}
67+
* @attr
68+
* @default false
69+
*/
70+
@property({ type: Boolean, reflect: true })
71+
readonly = false;
72+
6473
/**
6574
* Set to true if the component should have an error state.Property is reflected to the corresponding attribute.
6675
* @type {boolean}
@@ -226,7 +235,16 @@ export class UUISelectElement extends UUIFormControlMixin(LitElement, '') {
226235
`;
227236
}
228237

238+
private _getDisplayValue() {
239+
return (
240+
this.options.find(option => option.value === this.value)?.name ||
241+
this.value
242+
);
243+
}
244+
229245
render() {
246+
if (this.readonly) return html`<span>${this._getDisplayValue()}</span>`;
247+
230248
return html` <select
231249
id="native"
232250
aria-label=${this.label}

0 commit comments

Comments
 (0)