Skip to content

Commit

Permalink
fix(select): improve visualisation of the readOnly state
Browse files Browse the repository at this point in the history
  • Loading branch information
LucyChyzhova authored and Kiarokh committed Jan 31, 2025
1 parent f3bd180 commit 60d7f30
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
7 changes: 6 additions & 1 deletion src/components/select/select.scss
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@
margin-left: 0.25rem;
}

&.mdc-select--disabled {
&.mdc-select--disabled:not(.limel-select--readonly) {
.limel-select-trigger {
@include shared_input-select-picker.looks-disabled;
box-shadow: var(--button-shadow-normal);
Expand Down Expand Up @@ -157,6 +157,11 @@
}
}

.readonly-option {
position: absolute;
top: 1.145rem;
}

&.limel-select--required {
.mdc-floating-label::after {
content: '*';
Expand Down
13 changes: 8 additions & 5 deletions src/components/select/select.template.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -323,18 +323,21 @@ function getMenuOptionFilter(selectIsRequired: boolean) {
}

function getSelectedText(value: Option | Option[], readonly: boolean): string {
if ((!value || (isMultiple(value) && !value.length)) && readonly) {
return '–';
}
const emptyReadOnlyOption = <span class="readonly-option"></span>;

if (!value) {
return '';
const isEmptyValue = !value || (isMultiple(value) && !value.length);
if (isEmptyValue) {
return readonly ? emptyReadOnlyOption : '';
}

if (isMultiple(value)) {
return value.map((option) => option.text).join(', ');
}

if (readonly && (value.value === 'empty' || value.text === '')) {
return emptyReadOnlyOption;
}

return value.text;
}

Expand Down

0 comments on commit 60d7f30

Please sign in to comment.