Skip to content

Commit 4504ba8

Browse files
igauchfengtianze
authored andcommitted
feat: select support readonly
1 parent 5158fd4 commit 4504ba8

13 files changed

+55
-24
lines changed

.changeset/beige-bananas-grin.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@alauda/ui': minor
3+
---
4+
5+
- feat: select support readonly

src/form/common-form.ts

+4-2
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,16 @@ export class CommonFormControl<V, M = V> implements ControlValueAccessor {
2424
}
2525

2626
set disabled(val: boolean | '') {
27-
this._disabled = coerceAttrBoolean(val);
27+
this._disabled = this._readonly || coerceAttrBoolean(val);
2828
}
2929

3030
@Input()
3131
get readonly() {
32-
return this.disabled;
32+
return this._readonly;
3333
}
3434

3535
set readonly(val) {
36+
this._readonly = coerceAttrBoolean(val);
3637
this.disabled = val;
3738
}
3839

@@ -56,6 +57,7 @@ export class CommonFormControl<V, M = V> implements ControlValueAccessor {
5657
protected onTouched: () => void;
5758
private _propValue: V;
5859
private _disabled = false;
60+
private _readonly: boolean;
5961

6062
model: M = null;
6163
model$ = new ReplaySubject<M>(1);

src/input/input.component.scss

+8-4
Original file line numberDiff line numberDiff line change
@@ -46,20 +46,24 @@
4646
@include outline-shadow(primary);
4747
}
4848

49-
&[readonly] {
49+
&[disable],
50+
&[disabled] {
5051
background-color: use-rgb(n-8);
5152
border-color: use-rgb(n-7) !important;
52-
cursor: default;
5353
}
5454

5555
&[disabled] {
56-
background-color: use-rgb(n-8);
57-
border-color: use-rgb(n-7) !important;
5856
color: use-text-color(disabled);
5957
-webkit-text-fill-color: use-text-color(disabled);
6058
cursor: not-allowed;
6159
}
6260

61+
&[readonly] {
62+
color: use-text-color(main);
63+
-webkit-text-fill-color: use-text-color(main);
64+
cursor: default;
65+
}
66+
6367
&--large {
6468
height: use-var(inline-height-l);
6569
font-size: use-var(font-size-l);

src/paginator/__snapshots__/paginator.component.spec.ts.snap

+3-6
Original file line numberDiff line numberDiff line change
@@ -137,9 +137,8 @@ exports[`PaginatorComponent should change page size correctly 1`] = `
137137
<input
138138
aui-input=""
139139
autocomplete="off"
140-
class="aui-select__input aui-input aui-input--medium"
140+
class="aui-select__input aui-input aui-input--medium aui-select__input-inaction"
141141
placeholder=""
142-
readonly=""
143142
/>
144143
<div
145144
class="aui-input aui-input--medium aui-select__label-container"
@@ -415,9 +414,8 @@ exports[`PaginatorComponent should render current template 1`] = `
415414
<input
416415
aui-input=""
417416
autocomplete="off"
418-
class="aui-select__input aui-input aui-input--medium"
417+
class="aui-select__input aui-input aui-input--medium aui-select__input-inaction"
419418
placeholder=""
420-
readonly=""
421419
/>
422420
<div
423421
class="aui-input aui-input--medium aui-select__label-container"
@@ -702,10 +700,9 @@ exports[`PaginatorComponent should render current template 2`] = `
702700
<input
703701
aui-input=""
704702
autocomplete="off"
705-
class="aui-select__input aui-input aui-input--medium"
703+
class="aui-select__input aui-input aui-input--medium aui-select__input-inaction"
706704
disabled=""
707705
placeholder=""
708-
readonly=""
709706
/>
710707
<div
711708
class="aui-input aui-input--medium aui-select__label-container"

src/select/base-select.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ export abstract class BaseSelect<T, V = T>
9292
return this.tooltipRef.isCreated;
9393
}
9494

95-
get inputReadonly() {
95+
get inaction() {
9696
return !(this.filterable && this.opened);
9797
}
9898

src/select/multi-select/multi-select.component.html

+8-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
<div
22
[class]="rootClass"
3+
[ngClass]="{
4+
isDisabled: disabled,
5+
isFocused: focused,
6+
isClearable: displayClearBtn,
7+
withHeightLimit: maxRowCount > 0,
8+
isReadonly: readonly
9+
}"
310
#selectRef
411
#tooltipRef="auiTooltip"
512
[auiTooltip]="templateRef"
@@ -53,7 +60,7 @@
5360
<input
5461
#inputRef
5562
autocomplete="off"
56-
[readonly]="inputReadonly"
63+
[readonly]="readonly"
5764
[class]="inputClass"
5865
(focus)="onInputFocus()"
5966
(blur)="onInputBlur()"

src/select/multi-select/multi-select.component.scss

+9
Original file line numberDiff line numberDiff line change
@@ -49,4 +49,13 @@ $block: aui-multi-select;
4949
.aui-tag--info {
5050
background-color: use-rgb(n-10);
5151
}
52+
53+
&.isReadonly {
54+
cursor: default;
55+
56+
.aui-tag {
57+
color: use-text-color(main);
58+
background-color: use-rgb(n-10);
59+
}
60+
}
5261
}

src/select/multi-select/multi-select.component.ts

+2-6
Original file line numberDiff line numberDiff line change
@@ -137,11 +137,7 @@ export class MultiSelectComponent<T = unknown>
137137

138138
get rootClass() {
139139
const size = this.size || ComponentSize.Medium;
140-
return `aui-input ${this.bem.block(size)} ${
141-
this.disabled ? 'isDisabled' : ''
142-
} ${this.focused ? 'isFocused' : ''} ${
143-
this.displayClearBtn ? 'isClearable' : ''
144-
} ${this.maxRowCount > 0 ? 'withHeightLimit' : ''}`;
140+
return `aui-input ${this.bem.block(size)}`;
145141
}
146142

147143
get tagSize() {
@@ -152,7 +148,7 @@ export class MultiSelectComponent<T = unknown>
152148

153149
get inputClass() {
154150
return `${this.bem.element('input', {
155-
hidden: this.inputReadonly,
151+
hidden: this.inaction,
156152
})} aui-tag aui-tag--${this.tagSize}`;
157153
}
158154

src/select/select.component.html

+3-1
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,12 @@
1818
<input
1919
#inputRef
2020
class="aui-select__input"
21+
[class.aui-select__input-inaction]="inaction"
2122
autocomplete="off"
2223
aui-input
2324
[disabled]="disabled"
2425
[size]="size"
25-
[readonly]="inputReadonly"
26+
[readonly]="readonly"
2627
[placeholder]="!(hasSelected$ | async) ? placeholder : ''"
2728
(input)="onInput($event)"
2829
(keydown)="onKeyDown($event)"
@@ -46,6 +47,7 @@
4647
*ngIf="(selectedOption$ | async) && !filterString"
4748
class="aui-select__label-container aui-input aui-input--{{ size }}"
4849
[attr.disabled]="disabled ? true : null"
50+
[attr.readonly]="readonly ? true : null"
4951
>
5052
<div class="aui-select__label">
5153
<ng-container *ngIf="(selectedOption$ | async).label as optionLabel">

src/select/select.component.scss

+2-2
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
@include text-overflow;
3232
}
3333

34-
&__input.aui-input[readonly] {
34+
&__input-inaction {
3535
background-color: use-rgb(main-bg);
3636
border-color: use-rgb(n-7) !important;
3737
cursor: text;
@@ -41,7 +41,7 @@
4141
}
4242
}
4343

44-
&__input.aui-input[disabled] {
44+
&__input[disabled] {
4545
background-color: use-rgb(n-8);
4646
border-color: use-rgb(n-7);
4747
}

stories/select/basic.component.ts

+8-1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import { SelectModule } from 'src/select';
1515
[disabled]="disabled"
1616
[clearable]="clearable"
1717
[filterable]="filterable"
18+
[readonly]="readonly"
1819
placeholder="select a value"
1920
>
2021
<ng-container *auiOptionContent>
@@ -59,9 +60,15 @@ export default class SelectBasicComponent {
5960
@Input()
6061
filterable = true;
6162

63+
/**
64+
* 是否只读
65+
*/
66+
@Input()
67+
readonly = false;
68+
6269
arr = Array.from({ length: 11 })
6370
.fill(null)
6471
.map((_, i) => `option${i + 1}`);
6572

66-
value = '';
73+
value = 'option1';
6774
}

stories/select/basic.stories.ts

+1
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,6 @@ export const Basic: Story = {
2323
loading: false,
2424
clearable: false,
2525
filterable: true,
26+
readonly: false,
2627
},
2728
};

stories/select/select.mdx

+1
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ import * as multiple from './multiple.stories';
4444
| loading | boolean | false | 是否加载中 |
4545
| clearable | boolean | false | 选项是否可清除 |
4646
| filterable | boolean | true | 是否支持选项过滤 |
47+
| readonly | boolean | false | 是否只读 |
4748
| defaultFirstOption | boolean | true | 是否第一项作为默认选项 |
4849
| lazy | boolean | true | 关闭候选项时是否缓存 Option 组件 |
4950
| filterFn | OptionFilterFn | Array.property.includes | 自定义过滤方法,filterable 为 true 时设置 |

0 commit comments

Comments
 (0)