diff --git a/.changeset/beige-bananas-grin.md b/.changeset/beige-bananas-grin.md new file mode 100644 index 000000000..7d935b50b --- /dev/null +++ b/.changeset/beige-bananas-grin.md @@ -0,0 +1,5 @@ +--- +'@alauda/ui': minor +--- + +- feat: select support readonly diff --git a/src/form/common-form.ts b/src/form/common-form.ts index b0de43952..0c63dd800 100644 --- a/src/form/common-form.ts +++ b/src/form/common-form.ts @@ -24,15 +24,16 @@ export class CommonFormControl implements ControlValueAccessor { } set disabled(val: boolean | '') { - this._disabled = coerceAttrBoolean(val); + this._disabled = this._readonly || coerceAttrBoolean(val); } @Input() get readonly() { - return this.disabled; + return this._readonly; } set readonly(val) { + this._readonly = coerceAttrBoolean(val); this.disabled = val; } @@ -56,6 +57,7 @@ export class CommonFormControl implements ControlValueAccessor { protected onTouched: () => void; private _propValue: V; private _disabled = false; + private _readonly: boolean; model: M = null; model$ = new ReplaySubject(1); diff --git a/src/input/input.component.scss b/src/input/input.component.scss index a355600f2..24b6d3868 100644 --- a/src/input/input.component.scss +++ b/src/input/input.component.scss @@ -46,20 +46,24 @@ @include outline-shadow(primary); } - &[readonly] { + &[disable], + &[disabled] { background-color: use-rgb(n-8); border-color: use-rgb(n-7) !important; - cursor: default; } &[disabled] { - background-color: use-rgb(n-8); - border-color: use-rgb(n-7) !important; color: use-text-color(disabled); -webkit-text-fill-color: use-text-color(disabled); cursor: not-allowed; } + &[readonly] { + color: use-text-color(main); + -webkit-text-fill-color: use-text-color(main); + cursor: default; + } + &--large { height: use-var(inline-height-l); font-size: use-var(font-size-l); diff --git a/src/paginator/__snapshots__/paginator.component.spec.ts.snap b/src/paginator/__snapshots__/paginator.component.spec.ts.snap index 6e868e582..c1ef7420a 100644 --- a/src/paginator/__snapshots__/paginator.component.spec.ts.snap +++ b/src/paginator/__snapshots__/paginator.component.spec.ts.snap @@ -137,9 +137,8 @@ exports[`PaginatorComponent should change page size correctly 1`] = `
return this.tooltipRef.isCreated; } - get inputReadonly() { + get inaction() { return !(this.filterable && this.opened); } diff --git a/src/select/multi-select/multi-select.component.html b/src/select/multi-select/multi-select.component.html index 90c8f4adf..59cfe1818 100644 --- a/src/select/multi-select/multi-select.component.html +++ b/src/select/multi-select/multi-select.component.html @@ -1,5 +1,12 @@
get rootClass() { const size = this.size || ComponentSize.Medium; - return `aui-input ${this.bem.block(size)} ${ - this.disabled ? 'isDisabled' : '' - } ${this.focused ? 'isFocused' : ''} ${ - this.displayClearBtn ? 'isClearable' : '' - } ${this.maxRowCount > 0 ? 'withHeightLimit' : ''}`; + return `aui-input ${this.bem.block(size)}`; } get tagSize() { @@ -152,7 +148,7 @@ export class MultiSelectComponent get inputClass() { return `${this.bem.element('input', { - hidden: this.inputReadonly, + hidden: this.inaction, })} aui-tag aui-tag--${this.tagSize}`; } diff --git a/src/select/select.component.html b/src/select/select.component.html index 67607fb99..5f13a975e 100644 --- a/src/select/select.component.html +++ b/src/select/select.component.html @@ -18,11 +18,12 @@
diff --git a/src/select/select.component.scss b/src/select/select.component.scss index d21d7a301..ca11a23b0 100644 --- a/src/select/select.component.scss +++ b/src/select/select.component.scss @@ -31,7 +31,7 @@ @include text-overflow; } - &__input.aui-input[readonly] { + &__input-inaction { background-color: use-rgb(main-bg); border-color: use-rgb(n-7) !important; cursor: text; @@ -41,7 +41,7 @@ } } - &__input.aui-input[disabled] { + &__input[disabled] { background-color: use-rgb(n-8); border-color: use-rgb(n-7); } diff --git a/stories/select/basic.component.ts b/stories/select/basic.component.ts index 1b7006e4f..8af4724c6 100644 --- a/stories/select/basic.component.ts +++ b/stories/select/basic.component.ts @@ -15,6 +15,7 @@ import { SelectModule } from 'src/select'; [disabled]="disabled" [clearable]="clearable" [filterable]="filterable" + [readonly]="readonly" placeholder="select a value" > @@ -59,9 +60,15 @@ export default class SelectBasicComponent { @Input() filterable = true; + /** + * 是否只读 + */ + @Input() + readonly = false; + arr = Array.from({ length: 11 }) .fill(null) .map((_, i) => `option${i + 1}`); - value = ''; + value = 'option1'; } diff --git a/stories/select/basic.stories.ts b/stories/select/basic.stories.ts index 89d0b3ee6..3c15ab308 100644 --- a/stories/select/basic.stories.ts +++ b/stories/select/basic.stories.ts @@ -23,5 +23,6 @@ export const Basic: Story = { loading: false, clearable: false, filterable: true, + readonly: false, }, }; diff --git a/stories/select/select.mdx b/stories/select/select.mdx index 6432fbcca..c966822d7 100644 --- a/stories/select/select.mdx +++ b/stories/select/select.mdx @@ -44,6 +44,7 @@ import * as multiple from './multiple.stories'; | loading | boolean | false | 是否加载中 | | clearable | boolean | false | 选项是否可清除 | | filterable | boolean | true | 是否支持选项过滤 | +| readonly | boolean | false | 是否只读 | | defaultFirstOption | boolean | true | 是否第一项作为默认选项 | | lazy | boolean | true | 关闭候选项时是否缓存 Option 组件 | | filterFn | OptionFilterFn | Array.property.includes | 自定义过滤方法,filterable 为 true 时设置 |