@@ -33,6 +33,7 @@ interface TextboxProps {
33
33
$disabled ?: boolean ;
34
34
$isMobile : boolean ;
35
35
$isMultiselect ?: boolean ;
36
+ $readOnly ?: boolean ;
36
37
theme : ResolvedTheme ;
37
38
$valid : boolean ;
38
39
value : string ;
@@ -42,17 +43,47 @@ export interface DropdownListOption extends ListboxOption {
42
43
label : string ;
43
44
}
44
45
45
- function getBorderColor ( { $disabled, theme, $valid } : TextboxProps ) : string {
46
+ function getBackgroundColor ( { $disabled, $readOnly, theme } : TextboxProps ) : string {
47
+ if ( $disabled ) {
48
+ return theme . component [ 'dropdown-list-input-disabled-background-color' ] ;
49
+ }
50
+ if ( $readOnly ) {
51
+ return theme . component [ 'dropdown-list-input-readonly-background-color' ] ;
52
+ }
53
+
54
+ return theme . component [ 'dropdown-list-input-background-color' ] ;
55
+ }
56
+
57
+ function getBorderColor ( {
58
+ $disabled,
59
+ $readOnly,
60
+ theme,
61
+ $valid,
62
+ } : TextboxProps ) : string {
46
63
if ( $disabled ) {
47
64
return theme . component [ 'dropdown-list-input-disabled-border-color' ] ;
48
65
}
66
+ if ( $readOnly ) {
67
+ return theme . component [ 'dropdown-list-input-readonly-border-color' ] ;
68
+ }
49
69
if ( ! $valid ) {
50
70
return theme . component [ 'dropdown-list-input-error-border-color' ] ;
51
71
}
52
72
53
73
return theme . component [ 'dropdown-list-input-border-color' ] ;
54
74
}
55
75
76
+ function getTextColor ( { $disabled, $readOnly, theme } : TextboxProps ) : string {
77
+ if ( $disabled ) {
78
+ return theme . component [ 'dropdown-list-input-disabled-text-color' ] ;
79
+ }
80
+ if ( $readOnly ) {
81
+ return theme . component [ 'dropdown-list-input-readonly-text-color' ] ;
82
+ }
83
+
84
+ return theme . component [ 'dropdown-list-input-text-color' ] ;
85
+ }
86
+
56
87
const StyledFieldContainer = styled ( FieldContainer ) `
57
88
position: relative;
58
89
` ;
@@ -65,11 +96,11 @@ const StyledListbox = styled(Listbox)`
65
96
66
97
const Textbox = styled . div < TextboxProps > `
67
98
align-items: center;
68
- background-color: ${ ( { $disabled , theme } ) => ( $disabled ? theme . component [ 'dropdown-list-input-disabled-background-color' ] : theme . component [ 'dropdown-list-input-background-color' ] ) } ;
99
+ background-color: ${ getBackgroundColor } ;
69
100
border: 1px solid ${ getBorderColor } ;
70
101
border-radius: var(--border-radius);
71
102
box-sizing: border-box;
72
- color: ${ ( { $disabled , theme } ) => $disabled && theme . component [ 'dropdown-list-input-disabled-text-color' ] } ;
103
+ color: ${ getTextColor } ;
73
104
display: flex;
74
105
justify-content: space-between;
75
106
min-height: ${ ( { $isMobile } ) => ( $isMobile ? 'var(--size-2halfx)' : 'var(--size-2x)' ) } ;
@@ -102,10 +133,10 @@ const ListBoxTag = styled(Tag)`
102
133
}
103
134
` ;
104
135
105
- const Arrow = styled ( Icon ) < { $disabled ?: boolean } > `
136
+ const Arrow = styled ( Icon ) < { $disabled ?: boolean , $readOnly ?: boolean } > `
106
137
align-items: center;
107
138
color: ${ ( { $disabled, theme } ) => ( $disabled ? theme . component [ 'dropdown-list-arrow-disabled-color' ] : theme . component [ 'dropdown-list-arrow-color' ] ) } ;
108
- display: flex;
139
+ display: ${ ( { $readOnly } ) => ( $readOnly ? 'none' : ' flex' ) } ;
109
140
flex: none;
110
141
height: var(--size-1x);
111
142
margin-left: auto;
@@ -150,6 +181,7 @@ export interface DropdownListProps<M extends boolean | undefined> {
150
181
name ?: string ;
151
182
options : DropdownListOption [ ] ;
152
183
required ?: boolean ;
184
+ readOnly ?: boolean ;
153
185
tooltip ?: TooltipProps ;
154
186
toggletip ?: ToggletipProps ;
155
187
/**
@@ -200,6 +232,7 @@ export const DropdownList: VoidFunctionComponent<DropdownListProps<boolean | und
200
232
onClose,
201
233
options,
202
234
name,
235
+ readOnly,
203
236
required,
204
237
tooltip,
205
238
toggletip,
@@ -282,7 +315,7 @@ export const DropdownList: VoidFunctionComponent<DropdownListProps<boolean | und
282
315
}
283
316
284
317
function openListbox ( ) : void {
285
- if ( disabled ) {
318
+ if ( disabled || readOnly ) {
286
319
return ;
287
320
}
288
321
@@ -452,7 +485,7 @@ export const DropdownList: VoidFunctionComponent<DropdownListProps<boolean | und
452
485
aria-hidden = "true"
453
486
data-testid = { `listboxtag-${ option . value } ` }
454
487
key = { option . value }
455
- onRemove = { handleTagRemove }
488
+ onRemove = { readOnly ? undefined : handleTagRemove }
456
489
value = { { id : option . value , label : option . label } }
457
490
/>
458
491
) ) ;
@@ -502,6 +535,7 @@ export const DropdownList: VoidFunctionComponent<DropdownListProps<boolean | und
502
535
aria-expanded = { open }
503
536
aria-invalid = { ! valid ? 'true' : 'false' }
504
537
aria-labelledby = { ariaLabelledBy }
538
+ aria-readonly = { readOnly ? 'true' : 'false' }
505
539
aria-required = { required ? 'true' : 'false' }
506
540
data-testid = "textbox"
507
541
id = { id }
@@ -512,6 +546,7 @@ export const DropdownList: VoidFunctionComponent<DropdownListProps<boolean | und
512
546
onClick = { handleTextboxClick }
513
547
onKeyDown = { handleTextboxKeyDown }
514
548
ref = { textboxRef }
549
+ $readOnly = { readOnly }
515
550
role = "combobox"
516
551
tabIndex = { 0 }
517
552
$valid = { valid }
@@ -534,6 +569,7 @@ export const DropdownList: VoidFunctionComponent<DropdownListProps<boolean | und
534
569
aria-hidden = "true"
535
570
data-testid = "arrow"
536
571
$disabled = { disabled }
572
+ $readOnly = { readOnly }
537
573
name = { open ? 'chevronUp' : 'chevronDown' }
538
574
size = { device === 'mobile' ? '24' : '16' }
539
575
/>
0 commit comments