mirror of
https://github.com/ant-design/ant-design.git
synced 2025-06-07 09:26:06 +08:00
Remove span.ant-tag-text in Tag, and remove type casting in Dropdown (#9055)
* Remove span.ant-tag-text
Warp React.ReactNode with span element is not suggested. It may cause anti-specification problem: `<span><span>I'm spec breaker</span></span>`. span is not a general tags container.
Another benefit from this change is keeping the same structure with CheckableTag.
After inspecting the removing of the style of .ant-tag-text, seems bringing no problems. The old example employeed this css class has gone long long time ago. See: 0635877a51
* Use React.Children.only api to supress type casting
By codes, the children and the overlay of Dropdown must be **single** and **valid React.ReactElement**. React.Children.only takes it and report more friendly React internal built error messages.
* Revert hack CSS styles: filling .ant-tag's block area with orphan child anchor
This commit is contained in:
parent
d89ffcc5b2
commit
24e373a812
@ -49,16 +49,18 @@ export default class Dropdown extends React.Component<DropDownProps, any> {
|
||||
}
|
||||
|
||||
render() {
|
||||
const { children, prefixCls, overlay, trigger, disabled } = this.props;
|
||||
const dropdownTrigger = React.cloneElement(children as any, {
|
||||
className: classNames((children as any).props.className, `${prefixCls}-trigger`),
|
||||
const { children, prefixCls, overlay: overlayElements, trigger, disabled } = this.props;
|
||||
|
||||
const child = React.Children.only(children);
|
||||
const overlay = React.Children.only(overlayElements);
|
||||
|
||||
const dropdownTrigger = React.cloneElement(child, {
|
||||
className: classNames(child.props.className, `${prefixCls}-trigger`),
|
||||
disabled,
|
||||
});
|
||||
// menu cannot be selectable in dropdown defaultly
|
||||
const overlayProps = overlay && (overlay as any).props;
|
||||
const selectable = (overlayProps && 'selectable' in overlayProps)
|
||||
? overlayProps.selectable : false;
|
||||
const fixedModeOverlay = React.cloneElement(overlay as any, {
|
||||
const selectable = overlay.props.selectable || false;
|
||||
const fixedModeOverlay = React.cloneElement(overlay, {
|
||||
mode: 'vertical',
|
||||
selectable,
|
||||
});
|
||||
|
@ -6,35 +6,23 @@ exports[`renders ./components/tag/demo/basic.md correctly 1`] = `
|
||||
class="ant-tag"
|
||||
data-show="true"
|
||||
>
|
||||
<span
|
||||
class="ant-tag-text"
|
||||
>
|
||||
Tag 1
|
||||
</span>
|
||||
Tag 1
|
||||
</div>
|
||||
<div
|
||||
class="ant-tag"
|
||||
data-show="true"
|
||||
>
|
||||
<span
|
||||
class="ant-tag-text"
|
||||
<a
|
||||
href="https://github.com/ant-design/ant-design/issues/1862"
|
||||
>
|
||||
<a
|
||||
href="https://github.com/ant-design/ant-design/issues/1862"
|
||||
>
|
||||
Link
|
||||
</a>
|
||||
</span>
|
||||
Link
|
||||
</a>
|
||||
</div>
|
||||
<div
|
||||
class="ant-tag"
|
||||
data-show="true"
|
||||
>
|
||||
<span
|
||||
class="ant-tag-text"
|
||||
>
|
||||
Tag 2
|
||||
</span>
|
||||
Tag 2
|
||||
<i
|
||||
class="anticon anticon-cross"
|
||||
/>
|
||||
@ -43,11 +31,7 @@ exports[`renders ./components/tag/demo/basic.md correctly 1`] = `
|
||||
class="ant-tag"
|
||||
data-show="true"
|
||||
>
|
||||
<span
|
||||
class="ant-tag-text"
|
||||
>
|
||||
Prevent Default
|
||||
</span>
|
||||
Prevent Default
|
||||
<i
|
||||
class="anticon anticon-cross"
|
||||
/>
|
||||
@ -87,111 +71,67 @@ exports[`renders ./components/tag/demo/colorful.md correctly 1`] = `
|
||||
class="ant-tag ant-tag-magenta"
|
||||
data-show="true"
|
||||
>
|
||||
<span
|
||||
class="ant-tag-text"
|
||||
>
|
||||
magenta
|
||||
</span>
|
||||
magenta
|
||||
</div>
|
||||
<div
|
||||
class="ant-tag ant-tag-red"
|
||||
data-show="true"
|
||||
>
|
||||
<span
|
||||
class="ant-tag-text"
|
||||
>
|
||||
red
|
||||
</span>
|
||||
red
|
||||
</div>
|
||||
<div
|
||||
class="ant-tag ant-tag-volcano"
|
||||
data-show="true"
|
||||
>
|
||||
<span
|
||||
class="ant-tag-text"
|
||||
>
|
||||
volcano
|
||||
</span>
|
||||
volcano
|
||||
</div>
|
||||
<div
|
||||
class="ant-tag ant-tag-orange"
|
||||
data-show="true"
|
||||
>
|
||||
<span
|
||||
class="ant-tag-text"
|
||||
>
|
||||
orange
|
||||
</span>
|
||||
orange
|
||||
</div>
|
||||
<div
|
||||
class="ant-tag ant-tag-gold"
|
||||
data-show="true"
|
||||
>
|
||||
<span
|
||||
class="ant-tag-text"
|
||||
>
|
||||
gold
|
||||
</span>
|
||||
gold
|
||||
</div>
|
||||
<div
|
||||
class="ant-tag ant-tag-lime"
|
||||
data-show="true"
|
||||
>
|
||||
<span
|
||||
class="ant-tag-text"
|
||||
>
|
||||
lime
|
||||
</span>
|
||||
lime
|
||||
</div>
|
||||
<div
|
||||
class="ant-tag ant-tag-green"
|
||||
data-show="true"
|
||||
>
|
||||
<span
|
||||
class="ant-tag-text"
|
||||
>
|
||||
green
|
||||
</span>
|
||||
green
|
||||
</div>
|
||||
<div
|
||||
class="ant-tag ant-tag-cyan"
|
||||
data-show="true"
|
||||
>
|
||||
<span
|
||||
class="ant-tag-text"
|
||||
>
|
||||
cyan
|
||||
</span>
|
||||
cyan
|
||||
</div>
|
||||
<div
|
||||
class="ant-tag ant-tag-blue"
|
||||
data-show="true"
|
||||
>
|
||||
<span
|
||||
class="ant-tag-text"
|
||||
>
|
||||
blue
|
||||
</span>
|
||||
blue
|
||||
</div>
|
||||
<div
|
||||
class="ant-tag ant-tag-geekblue"
|
||||
data-show="true"
|
||||
>
|
||||
<span
|
||||
class="ant-tag-text"
|
||||
>
|
||||
geekblue
|
||||
</span>
|
||||
geekblue
|
||||
</div>
|
||||
<div
|
||||
class="ant-tag ant-tag-purple"
|
||||
data-show="true"
|
||||
>
|
||||
<span
|
||||
class="ant-tag-text"
|
||||
>
|
||||
purple
|
||||
</span>
|
||||
purple
|
||||
</div>
|
||||
</div>
|
||||
<h4
|
||||
@ -205,44 +145,28 @@ exports[`renders ./components/tag/demo/colorful.md correctly 1`] = `
|
||||
data-show="true"
|
||||
style="background-color:#f50"
|
||||
>
|
||||
<span
|
||||
class="ant-tag-text"
|
||||
>
|
||||
#f50
|
||||
</span>
|
||||
#f50
|
||||
</div>
|
||||
<div
|
||||
class="ant-tag ant-tag-has-color"
|
||||
data-show="true"
|
||||
style="background-color:#2db7f5"
|
||||
>
|
||||
<span
|
||||
class="ant-tag-text"
|
||||
>
|
||||
#2db7f5
|
||||
</span>
|
||||
#2db7f5
|
||||
</div>
|
||||
<div
|
||||
class="ant-tag ant-tag-has-color"
|
||||
data-show="true"
|
||||
style="background-color:#87d068"
|
||||
>
|
||||
<span
|
||||
class="ant-tag-text"
|
||||
>
|
||||
#87d068
|
||||
</span>
|
||||
#87d068
|
||||
</div>
|
||||
<div
|
||||
class="ant-tag ant-tag-has-color"
|
||||
data-show="true"
|
||||
style="background-color:#108ee9"
|
||||
>
|
||||
<span
|
||||
class="ant-tag-text"
|
||||
>
|
||||
#108ee9
|
||||
</span>
|
||||
#108ee9
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@ -254,21 +178,13 @@ exports[`renders ./components/tag/demo/control.md correctly 1`] = `
|
||||
class="ant-tag"
|
||||
data-show="true"
|
||||
>
|
||||
<span
|
||||
class="ant-tag-text"
|
||||
>
|
||||
Unremovable
|
||||
</span>
|
||||
Unremovable
|
||||
</div>
|
||||
<div
|
||||
class="ant-tag"
|
||||
data-show="true"
|
||||
>
|
||||
<span
|
||||
class="ant-tag-text"
|
||||
>
|
||||
Tag 2
|
||||
</span>
|
||||
Tag 2
|
||||
<i
|
||||
class="anticon anticon-cross"
|
||||
/>
|
||||
@ -277,11 +193,7 @@ exports[`renders ./components/tag/demo/control.md correctly 1`] = `
|
||||
class="ant-tag"
|
||||
data-show="true"
|
||||
>
|
||||
<span
|
||||
class="ant-tag-text"
|
||||
>
|
||||
Tag 3
|
||||
</span>
|
||||
Tag 3
|
||||
<i
|
||||
class="anticon anticon-cross"
|
||||
/>
|
||||
@ -291,14 +203,10 @@ exports[`renders ./components/tag/demo/control.md correctly 1`] = `
|
||||
data-show="true"
|
||||
style="background:#fff;border-style:dashed"
|
||||
>
|
||||
<span
|
||||
class="ant-tag-text"
|
||||
>
|
||||
<i
|
||||
class="anticon anticon-plus"
|
||||
/>
|
||||
New Tag
|
||||
</span>
|
||||
<i
|
||||
class="anticon anticon-plus"
|
||||
/>
|
||||
New Tag
|
||||
</div>
|
||||
</div>
|
||||
`;
|
||||
|
@ -106,7 +106,7 @@ export default class Tag extends React.Component<TagProps, TagState> {
|
||||
className={classString}
|
||||
style={tagStyle}
|
||||
>
|
||||
<span className={`${prefixCls}-text`}>{children}</span>
|
||||
{children}
|
||||
{closeIcon}
|
||||
</div>
|
||||
);
|
||||
|
@ -29,12 +29,10 @@
|
||||
color: @tag-default-color;
|
||||
}
|
||||
|
||||
&-text {
|
||||
a:first-child:last-child {
|
||||
display: inline-block;
|
||||
margin: 0 -8px;
|
||||
padding: 0 8px;
|
||||
}
|
||||
>a:first-child:last-child {
|
||||
display: inline-block;
|
||||
margin: 0 -8px;
|
||||
padding: 0 8px;
|
||||
}
|
||||
|
||||
.@{iconfont-css-prefix}-cross {
|
||||
|
Loading…
Reference in New Issue
Block a user