Skip to content

Commit 2107de0

Browse files
committed
Readonly of select
1 parent 338ca32 commit 2107de0

File tree

1 file changed

+21
-11
lines changed

1 file changed

+21
-11
lines changed

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

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,13 @@ declare global {
2828
* @cssprop --uui-select-padding-x - Padding on the x axis
2929
* @cssprop --uui-select-border-color - Border color
3030
* @cssprop --uui-select-border-color-hover - Border color on hover
31+
* @cssprop --uui-select-border-color-readonly - Border color when readonly
3132
* @cssprop --uui-select-selected-option-background-color - Background color of the selected option
3233
* @cssprop --uui-select-selected-option-color - Color of the selected option
3334
* @cssprop --uui-select-outline-color - Outline color
3435
* @cssprop --uui-select-background-color - Background color
35-
* @cssprop --uui-select-disabled-background-color - Background color when disabled
36+
* @cssprop --uui-select-background-color-disabled - Background color when disabled
37+
* @cssprop --uui-select-background-color-readonly - Background color when readonly
3638
* @extends UUIFormControlMixin
3739
*/
3840
// TODO: Consider if this should use child items instead of an array.
@@ -237,21 +239,13 @@ export class UUISelectElement extends UUIFormControlMixin(LitElement, '') {
237239
`;
238240
}
239241

240-
private _getDisplayValue() {
241-
return (
242-
this.options.find(option => option.value === this.value)?.name ||
243-
this.value
244-
);
245-
}
246-
247242
render() {
248-
if (this.readonly) return html`<span>${this._getDisplayValue()}</span>`;
249-
250243
return html` <select
251244
id="native"
252245
aria-label=${this.label}
253246
@change=${this.setValue}
254247
?disabled=${this.disabled}
248+
aria-readonly=${this.readonly ? 'true' : 'false'}
255249
.name=${this.name}
256250
.value=${this.value as string}>
257251
<option disabled selected value="" hidden>${this.placeholder}</option>
@@ -305,9 +299,25 @@ export class UUISelectElement extends UUIFormControlMixin(LitElement, '') {
305299
#native[disabled] {
306300
cursor: not-allowed;
307301
background-color: var(
308-
--uui-select-disabled-background-color,
302+
--uui-select-background-color-disabled,
303+
var(--uui-color-disabled)
304+
);
305+
border-color: var(
306+
--uui-select-border-color-disabled,
307+
var(--uui-color-disabled)
308+
);
309+
}
310+
311+
#native[aria-readonly='true'] {
312+
pointer-events: none;
313+
background-color: var(
314+
--uui-select-background-color-readonly,
309315
var(--uui-color-disabled)
310316
);
317+
border-color: var(
318+
--uui-select-border-color-readonly,
319+
var(--uui-color-disabled-standalone)
320+
);
311321
}
312322
313323
#native:hover {

0 commit comments

Comments
 (0)