Skip to content

Feat Tag CheckableTag #2400

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Jun 12, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions components/tag/CheckableTag.jsx
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
import { inject } from 'vue';
import PropTypes from '../_util/vue-types';
import { ConfigConsumerProps } from '../config-provider';

export default {
name: 'ACheckableTag',
model: {
prop: 'checked',
},
props: {
prefixCls: PropTypes.string,
checked: Boolean,
checked: PropTypes.bool,
},
inject: {
configProvider: { default: () => ConfigConsumerProps },
setup() {
return {
configProvider: inject('configProvider', ConfigConsumerProps),
};
},
computed: {
classes() {
Expand All @@ -28,15 +28,15 @@ export default {
methods: {
handleClick() {
const { checked } = this;
this.$emit('input', !checked);
this.$emit('update:checked', !checked);
this.$emit('change', !checked);
},
},
render() {
const { classes, handleClick, $slots } = this;
return (
<div class={classes} onClick={handleClick}>
{$slots.default}
{$slots.default && $slots.default()}
</div>
);
},
Expand Down
26 changes: 9 additions & 17 deletions components/tag/Tag.jsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import { Transition } from 'vue';
import { Transition, inject } from 'vue';
import CloseOutlined from '@ant-design/icons-vue/CloseOutlined';
import PropTypes from '../_util/vue-types';
import getTransitionProps from '../_util/getTransitionProps';
import omit from 'omit.js';
import Wave from '../_util/wave';
import { hasProp, getListeners, getOptionProps } from '../_util/props-util';
import { hasProp, getOptionProps } from '../_util/props-util';
import BaseMixin from '../_util/BaseMixin';
import { ConfigConsumerProps } from '../config-provider';
import warning from '../_util/warning';
Expand All @@ -29,19 +28,17 @@ const PresetColorRegex = new RegExp(`^(${PresetColorTypes.join('|')})(-inverse)?
export default {
name: 'ATag',
mixins: [BaseMixin],
model: {
prop: 'visible',
event: 'close.visible',
},
props: {
prefixCls: PropTypes.string,
color: PropTypes.string,
closable: PropTypes.bool.def(false),
visible: PropTypes.bool,
afterClose: PropTypes.func,
},
inject: {
configProvider: { default: () => ConfigConsumerProps },
setup() {
return {
configProvider: inject('configProvider', ConfigConsumerProps),
};
},
data() {
let _visible = true;
Expand All @@ -68,7 +65,7 @@ export default {
methods: {
setVisible(visible, e) {
this.$emit('close', e);
this.$emit('close.visible', false);
this.$emit('update:visible', false);
const afterClose = this.afterClose;
if (afterClose) {
// next version remove.
Expand Down Expand Up @@ -120,16 +117,11 @@ export default {

render() {
const { prefixCls: customizePrefixCls } = this.$props;
const getPrefixCls = this.configProvider().getPrefixCls;
const getPrefixCls = this.configProvider.getPrefixCls;
const prefixCls = getPrefixCls('tag', customizePrefixCls);
const { _visible: visible } = this.$data;
const tag = (
<span
v-show={visible}
{...{ on: omit(getListeners(this), ['close']) }}
class={this.getTagClassName(prefixCls)}
style={this.getTagStyle()}
>
<span v-show={visible} class={this.getTagClassName(prefixCls)} style={this.getTagStyle()}>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

事件不需要了吗

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

没注意这个不是根节点,那我加上 {...omit(this.$attr,['close'])} 就行了吗?要不要过滤掉不是 on 开头的 attr 呢? @Amour1688

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

['onClose']

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里还真不需要 单独挂载事件
没有设置 inheritAttrs: false, 的情况下,事件也会被默认挂载到 根节点上
这里的 close 事件绑定到根节点也没关系
😓

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

好像是这样的,我一开始以为根节点是指的 Wave 组件上,不会往下传了。现在测了下应该是挂载到了实际的根节点上。

{this.$slots.default()}
{this.renderCloseIcon()}
</span>
Expand Down
8 changes: 3 additions & 5 deletions components/tag/index.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
import Tag from './Tag';
import CheckableTag from './CheckableTag';
import Base from '../base';

Tag.CheckableTag = CheckableTag;

/* istanbul ignore next */
Tag.install = function(Vue) {
Vue.use(Base);
Vue.component(Tag.name, Tag);
Vue.component(Tag.CheckableTag.name, Tag.CheckableTag);
Tag.install = function(app) {
app.component(Tag.name, Tag);
app.component(Tag.CheckableTag.name, Tag.CheckableTag);
};

export default Tag;
2 changes: 2 additions & 0 deletions examples/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import Col from 'ant-design-vue/col';
import Row from 'ant-design-vue/row';
import Tooltip from 'ant-design-vue/tooltip';
import Descriptions from 'ant-design-vue/descriptions';
import Tag from 'ant-design-vue/tag';
import 'ant-design-vue/style.js';

createApp(App)
Expand All @@ -44,4 +45,5 @@ createApp(App)
.use(Row)
.use(Tooltip)
.use(Descriptions)
.use(Tag)
.mount('#app');