Skip to content

Commit

Permalink
feat: readonly state for boolean base class
Browse files Browse the repository at this point in the history
  • Loading branch information
madsrasmussen authored and iOvergaard committed Jul 25, 2024
1 parent e63c245 commit 2c5c5a3
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions packages/uui-boolean-input/lib/uui-boolean-input.element.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,15 @@ export abstract class UUIBooleanInputElement extends UUIFormControlMixin(
@property({ type: Boolean, reflect: true })
disabled = false;

/**
* Sets the input to readonly mode, meaning value cannot be changed but still able to read and select its content.
* @type {boolean}
* @attr
* @default false
*/
@property({ type: Boolean, reflect: true })
readonly = false;

@query('#input')
protected _input!: HTMLInputElement;

Expand Down Expand Up @@ -176,7 +185,7 @@ export abstract class UUIBooleanInputElement extends UUIFormControlMixin(
id="input"
type="checkbox"
@change="${this._onInputChange}"
.disabled=${this.disabled}
.disabled=${this.disabled || this.readonly}
.checked=${this.checked}
aria-checked="${this.checked ? 'true' : 'false'}"
aria-label=${this.label}
Expand All @@ -196,14 +205,18 @@ export abstract class UUIBooleanInputElement extends UUIFormControlMixin(
position: relative;
cursor: pointer;
user-select: none;
display: flex;
flex-wrap: nowrap;
align-items: center;
justify-items: center;
gap: var(--uui-size-3);
}
:host([readonly]) label {
cursor: text;
user-select: auto;
}
input {
position: absolute;
height: 0px;
Expand Down

0 comments on commit 2c5c5a3

Please sign in to comment.