Skip to content

Commit 770277b

Browse files
feat: add readonly state for combobox (#2981)
1 parent 33ec22a commit 770277b

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

src/combobox/combobox.component.ts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ import { Observable } from "rxjs";
6363
'cds--list-box--md': size === 'md',
6464
'cds--list-box--lg': size === 'lg',
6565
'cds--list-box--disabled': disabled,
66+
'cds--combo-box--readonly': readonly,
6667
'cds--combo-box--warning cds--list-box--warning': warn
6768
}"
6869
class="cds--list-box cds--combo-box"
@@ -74,7 +75,7 @@ import { Observable } from "rxjs";
7475
<div
7576
*ngIf="type === 'multi' && pills.length > 0"
7677
class="cds--tag cds--tag--filter cds--tag--high-contrast"
77-
[ngClass]="{'cds--tag--disabled': disabled}">
78+
[ngClass]="{'cds--tag--disabled': disabled || readonly}">
7879
<span class="cds--tag__label">{{ pills.length }}</span>
7980
<button
8081
type="button"
@@ -84,7 +85,7 @@ import { Observable } from "rxjs";
8485
class="cds--tag__close-icon"
8586
tabindex="0"
8687
[title]="clearSelectionsTitle"
87-
[disabled]="disabled"
88+
[disabled]="disabled || readonly"
8889
[attr.aria-label]="clearSelectionAria">
8990
<svg
9091
focusable="false"
@@ -106,6 +107,7 @@ import { Observable } from "rxjs";
106107
autocomplete="off"
107108
role="combobox"
108109
[disabled]="disabled"
110+
[readOnly]="readonly"
109111
(input)="onSearch($event.target.value)"
110112
(blur)="onBlur()"
111113
(keydown.enter)="onSubmit($event)"
@@ -362,6 +364,10 @@ export class ComboBox implements OnChanges, AfterViewInit, AfterContentInit, OnD
362364
* Set to `true` to disable combobox.
363365
*/
364366
@Input() disabled = false;
367+
/**
368+
* Set to `true` for readonly state.
369+
*/
370+
@Input() readonly = false;
365371
/**
366372
* Emits a ListItem
367373
*
@@ -697,7 +703,7 @@ export class ComboBox implements OnChanges, AfterViewInit, AfterContentInit, OnD
697703
* Opens the dropdown.
698704
*/
699705
public openDropdown() {
700-
if (this.disabled) { return; }
706+
if (this.disabled || this.readonly) { return; }
701707
this.open = true;
702708
this._dropUp = false;
703709

@@ -778,7 +784,7 @@ export class ComboBox implements OnChanges, AfterViewInit, AfterContentInit, OnD
778784
event.stopPropagation();
779785
event.preventDefault();
780786

781-
if (this.disabled) {
787+
if (this.disabled || this.readonly) {
782788
return;
783789
}
784790

src/combobox/combobox.stories.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ export default {
3131
hideLabel: false,
3232
helperText: "Optional helper text",
3333
disabled: false,
34+
readonly: false,
3435
invalid: false,
3536
invalidText: "A valid value is required",
3637
warn: false,
@@ -105,6 +106,7 @@ const Template = (args) => ({
105106
<cds-combo-box
106107
[(ngModel)]="model"
107108
[disabled]="disabled"
109+
[readonly]="readonly"
108110
[invalid]="invalid"
109111
[size]="size"
110112
[appendInline]="appendInline"
@@ -185,6 +187,7 @@ const MultiTemplate = (args) => ({
185187
[hideLabel]="hideLabel"
186188
[warn]="warn"
187189
[disabled]="disabled"
190+
[readonly]="readonly"
188191
[size]="size"
189192
[helperText]="helperText"
190193
[appendInline]="false"

0 commit comments

Comments
 (0)