diff --git a/docs/en-US/component/tag.md b/docs/en-US/component/tag.md index 47a2734693..54eb80af73 100644 --- a/docs/en-US/component/tag.md +++ b/docs/en-US/component/tag.md @@ -105,10 +105,11 @@ tag/checkable ### CheckTag Attributes -| Name | Description | Type | Default | -| ------------------------- | ---------------- | ------------------------------------------------------------------ | ------- | -| checked / v-model:checked | is checked | ^[boolean] | false | -| type ^(2.5.4) | type of CheckTag | ^[enum]`'primary' \| 'success' \| 'info' \| 'warning' \| 'danger'` | primary | +| Name | Description | Type | Default | +| ------------------------- | --------------------------------- | ------------------------------------------------------------------ | ------- | +| checked / v-model:checked | is checked | ^[boolean] | false | +| disabled ^(2.8.2) | whether the check-tag is disabled | ^[boolean] | false | +| type ^(2.5.4) | type of CheckTag | ^[enum]`'primary' \| 'success' \| 'info' \| 'warning' \| 'danger'` | primary | ### CheckTag Events diff --git a/docs/examples/tag/checkable.vue b/docs/examples/tag/checkable.vue index d75780cafd..7c86c7792c 100644 --- a/docs/examples/tag/checkable.vue +++ b/docs/examples/tag/checkable.vue @@ -2,6 +2,7 @@
Checked Toggle me + Disabled
@@ -19,6 +20,14 @@ Tag 5 + + Tag 6 +
@@ -31,6 +40,7 @@ const checked2 = ref(true) const checked3 = ref(true) const checked4 = ref(true) const checked5 = ref(true) +const checked6 = ref(true) const onChange = (status: boolean) => { checked.value = status @@ -55,4 +65,8 @@ const onChange4 = (status: boolean) => { const onChange5 = (status: boolean) => { checked5.value = status } + +const onChange6 = (status: boolean) => { + checked6.value = status +} diff --git a/packages/components/check-tag/__tests__/check-tag.test.tsx b/packages/components/check-tag/__tests__/check-tag.test.tsx index aad7630f3a..4b53b58cf8 100644 --- a/packages/components/check-tag/__tests__/check-tag.test.tsx +++ b/packages/components/check-tag/__tests__/check-tag.test.tsx @@ -14,6 +14,7 @@ describe('CheckTag.vue', () => { expect(wrapper.text()).toEqual(AXIOM) expect(wrapper.classes()).toContain('el-check-tag') + expect(wrapper.classes()).not.toContain('is-disabled') }) test('functionality', async () => { @@ -40,4 +41,27 @@ describe('CheckTag.vue', () => { expect(wrapper.vm.checked).toBe(false) }) + + test('disabled', async () => { + const wrapper = mount({ + data: () => ({ checked: false }), + render() { + return ( + (this.checked = !this.checked)} + checked={this.checked} + > + {AXIOM} + + ) + }, + }) + expect(wrapper.text()).toEqual(AXIOM) + expect(wrapper.classes()).toContain('is-disabled') + + await wrapper.find('.el-check-tag').trigger('click') + + expect(wrapper.vm.checked).toBe(false) + }) }) diff --git a/packages/components/check-tag/src/check-tag.ts b/packages/components/check-tag/src/check-tag.ts index 2977ea30ad..f348613338 100644 --- a/packages/components/check-tag/src/check-tag.ts +++ b/packages/components/check-tag/src/check-tag.ts @@ -9,6 +9,10 @@ export const checkTagProps = buildProps({ * @description is checked */ checked: Boolean, + /** + * @description whether the check-tag is disabled + */ + disabled: Boolean, /** * @description type of Tag */ diff --git a/packages/components/check-tag/src/check-tag.vue b/packages/components/check-tag/src/check-tag.vue index 596fbddcee..831830a98a 100644 --- a/packages/components/check-tag/src/check-tag.vue +++ b/packages/components/check-tag/src/check-tag.vue @@ -17,13 +17,17 @@ const props = defineProps(checkTagProps) const emit = defineEmits(checkTagEmits) const ns = useNamespace('check-tag') +const isDisabled = computed(() => props.disabled) const containerKls = computed(() => [ ns.b(), ns.is('checked', props.checked), + ns.is('disabled', isDisabled.value), ns.m(props.type || 'primary'), ]) const handleChange = () => { + if (isDisabled.value) return + const checked = !props.checked emit(CHANGE_EVENT, checked) emit('update:checked', checked) diff --git a/packages/theme-chalk/src/check-tag.scss b/packages/theme-chalk/src/check-tag.scss index 017febb554..0aa76a03f0 100644 --- a/packages/theme-chalk/src/check-tag.scss +++ b/packages/theme-chalk/src/check-tag.scss @@ -17,15 +17,43 @@ background-color: getCssVar('color', 'info', 'light-7'); } - @include when(checked) { - @each $type in $types { - &.#{bem('check-tag', '', $type)} { + @each $type in $types { + &.#{bem('check-tag', '', $type)} { + @include when(checked) { background-color: getCssVar('color', $type, 'light-8'); color: getCssVar('color', $type); &:hover { background-color: getCssVar('color', $type, 'light-7'); } + + @include when(disabled) { + background-color: getCssVar('color', $type, 'light-8'); + color: getCssVar('disabled-text-color'); + cursor: not-allowed; + + &:hover { + background-color: getCssVar('color', $type, 'light-8'); + } + } + } + + @include when(disabled) { + @if $type == 'primary' { + background-color: getCssVar('color', 'info', 'light-9'); + } @else { + background-color: getCssVar('color', $type, 'light-9'); + } + color: getCssVar('disabled-text-color'); + cursor: not-allowed; + + &:hover { + @if $type == 'primary' { + background-color: getCssVar('color', 'info', 'light-9'); + } @else { + background-color: getCssVar('color', $type, 'light-9'); + } + } } } }