Skip to content

Commit 78ebbdd

Browse files
madsrasmusseniOvergaard
authored andcommitted
feat: readonly state for boolean base class
1 parent aec19fc commit 78ebbdd

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

packages/uui-boolean-input/lib/uui-boolean-input.element.ts

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,15 @@ export abstract class UUIBooleanInputElement extends UUIFormControlMixin(
8585
@property({ type: Boolean, reflect: true })
8686
disabled = false;
8787

88+
/**
89+
* Sets the input to readonly mode, meaning value cannot be changed but still able to read and select its content.
90+
* @type {boolean}
91+
* @attr
92+
* @default false
93+
*/
94+
@property({ type: Boolean, reflect: true })
95+
readonly = false;
96+
8897
@query('#input')
8998
protected _input!: HTMLInputElement;
9099

@@ -176,7 +185,7 @@ export abstract class UUIBooleanInputElement extends UUIFormControlMixin(
176185
id="input"
177186
type="checkbox"
178187
@change="${this._onInputChange}"
179-
.disabled=${this.disabled}
188+
.disabled=${this.disabled || this.readonly}
180189
.checked=${this.checked}
181190
aria-checked="${this.checked ? 'true' : 'false'}"
182191
aria-label=${this.label}
@@ -196,14 +205,18 @@ export abstract class UUIBooleanInputElement extends UUIFormControlMixin(
196205
position: relative;
197206
cursor: pointer;
198207
user-select: none;
199-
200208
display: flex;
201209
flex-wrap: nowrap;
202210
align-items: center;
203211
justify-items: center;
204212
gap: var(--uui-size-3);
205213
}
206214
215+
:host([readonly]) label {
216+
cursor: text;
217+
user-select: auto;
218+
}
219+
207220
input {
208221
position: absolute;
209222
height: 0px;

0 commit comments

Comments
 (0)