fix: some component not support css scoped

pull/2740/head
tanjinzhou 2020-08-20 17:56:49 +08:00
parent 63e87471d6
commit 4bdb241aa6
13 changed files with 102 additions and 32 deletions

@ -1 +1 @@
Subproject commit 38ec9e4d590312ac56c01203ae13453bdf36a0c7 Subproject commit 31e7b308adb6eabb97c003fbc7883e4d00c8f764

View File

@ -48,4 +48,13 @@ function resolvePropValue(options, props, key, value) {
return value; return value;
} }
export function getDataAndAriaProps(props) {
return Object.keys(props).reduce((memo, key) => {
if (key.substr(0, 5) === 'data-' || key.substr(0, 5) === 'aria-') {
memo[key] = props[key];
}
return memo;
}, {});
}
export { isOn, cacheStringFunction, camelize, hyphenate, capitalize, resolvePropValue }; export { isOn, cacheStringFunction, camelize, hyphenate, capitalize, resolvePropValue };

View File

@ -272,7 +272,6 @@ export default {
$slots, $slots,
getContainer, getContainer,
} = this; } = this;
const getPrefixCls = this.configProvider.getPrefixCls; const getPrefixCls = this.configProvider.getPrefixCls;
const prefixCls = getPrefixCls('anchor', customizePrefixCls); const prefixCls = getPrefixCls('anchor', customizePrefixCls);
this._sPrefixCls = prefixCls; this._sPrefixCls = prefixCls;
@ -281,7 +280,7 @@ export default {
visible: activeLink, visible: activeLink,
}); });
const wrapperClass = classNames(this.$attrs.class, this.wrapperClass, `${prefixCls}-wrapper`); const wrapperClass = classNames(this.wrapperClass, `${prefixCls}-wrapper`);
const anchorClass = classNames(prefixCls, { const anchorClass = classNames(prefixCls, {
fixed: !affix && !showInkInFixed, fixed: !affix && !showInkInFixed,
@ -290,9 +289,7 @@ export default {
const wrapperStyle = { const wrapperStyle = {
maxHeight: offsetTop ? `calc(100vh - ${offsetTop}px)` : '100vh', maxHeight: offsetTop ? `calc(100vh - ${offsetTop}px)` : '100vh',
...this.wrapperStyle, ...this.wrapperStyle,
...this.$attrs.style,
}; };
const anchorContent = ( const anchorContent = (
<div class={wrapperClass} style={wrapperStyle}> <div class={wrapperClass} style={wrapperStyle}>
<div class={anchorClass}> <div class={anchorClass}>
@ -307,7 +304,7 @@ export default {
return !affix ? ( return !affix ? (
anchorContent anchorContent
) : ( ) : (
<Affix offsetTop={offsetTop} target={getContainer}> <Affix {...this.$attrs} offsetTop={offsetTop} target={getContainer}>
{anchorContent} {anchorContent}
</Affix> </Affix>
); );

View File

@ -23,6 +23,7 @@ export default {
registerLink: noop, registerLink: noop,
unregisterLink: noop, unregisterLink: noop,
scrollTo: noop, scrollTo: noop,
$data: {},
}), }),
antAnchorContext: inject('antAnchorContext', {}), antAnchorContext: inject('antAnchorContext', {}),
configProvider: inject('configProvider', ConfigConsumerProps), configProvider: inject('configProvider', ConfigConsumerProps),
@ -62,7 +63,7 @@ export default {
const prefixCls = getPrefixCls('anchor', customizePrefixCls); const prefixCls = getPrefixCls('anchor', customizePrefixCls);
const title = getComponent(this, 'title'); const title = getComponent(this, 'title');
const active = this.antAnchor.activeLink === href; const active = this.antAnchor.$data.activeLink === href;
const wrapperClassName = classNames(`${prefixCls}-link`, { const wrapperClassName = classNames(`${prefixCls}-link`, {
[`${prefixCls}-link-active`]: active, [`${prefixCls}-link-active`]: active,
}); });

View File

@ -153,7 +153,7 @@ const Carousel = {
if (props.effect === 'fade') { if (props.effect === 'fade') {
props.fade = true; props.fade = true;
} }
const { class: cls, style, ...restAttrs } = this.$attrs;
const getPrefixCls = this.configProvider.getPrefixCls; const getPrefixCls = this.configProvider.getPrefixCls;
let className = getPrefixCls('carousel', props.prefixCls); let className = getPrefixCls('carousel', props.prefixCls);
const dotsClass = 'slick-dots'; const dotsClass = 'slick-dots';
@ -162,17 +162,19 @@ const Carousel = {
props.dotsClass = classNames(`${dotsClass}`, `${dotsClass}-${dotPosition || 'bottom'}`, { props.dotsClass = classNames(`${dotsClass}`, `${dotsClass}-${dotPosition || 'bottom'}`, {
[`${props.dotsClass}`]: !!props.dotsClass, [`${props.dotsClass}`]: !!props.dotsClass,
}); });
if (props.vertical) { className = classNames({
className = `${className} ${className}-vertical`; [cls]: !!cls,
} [className]: !!className,
[`${className}-vertical`]: props.vertical,
});
const SlickCarouselProps = { const SlickCarouselProps = {
...props, ...props,
...this.$attrs, ...restAttrs,
nextArrow: getComponent(this, 'nextArrow'), nextArrow: getComponent(this, 'nextArrow'),
prevArrow: getComponent(this, 'prevArrow'), prevArrow: getComponent(this, 'prevArrow'),
}; };
return ( return (
<div class={className}> <div class={className} style={style}>
<SlickCarousel ref={this.saveSlick} {...SlickCarouselProps} vSlots={$slots}></SlickCarousel> <SlickCarousel ref={this.saveSlick} {...SlickCarouselProps} vSlots={$slots}></SlickCarousel>
</div> </div>
); );

View File

@ -13,6 +13,7 @@ import { hasProp, getOptionProps, initDefaultProps, getComponent } from '../_uti
import BaseMixin from '../_util/BaseMixin'; import BaseMixin from '../_util/BaseMixin';
import { formatDate } from './utils'; import { formatDate } from './utils';
import InputIcon from './InputIcon'; import InputIcon from './InputIcon';
import { getDataAndAriaProps } from '../_util/util';
function getShowDateFromValue(value, mode) { function getShowDateFromValue(value, mode) {
const [start, end] = value; const [start, end] = value;
@ -413,6 +414,7 @@ export default {
onBlur={onBlur} onBlur={onBlur}
onMouseenter={this.onMouseEnter} onMouseenter={this.onMouseEnter}
onMouseleave={this.onMouseLeave} onMouseleave={this.onMouseLeave}
{...getDataAndAriaProps(props)}
> >
<VcDatePicker {...vcDatePickerProps} vSlots={{ default: input, ...$slots }}></VcDatePicker> <VcDatePicker {...vcDatePickerProps} vSlots={{ default: input, ...$slots }}></VcDatePicker>
</span> </span>

View File

@ -10,6 +10,7 @@ import BaseMixin from '../_util/BaseMixin';
import { WeekPickerProps } from './interface'; import { WeekPickerProps } from './interface';
import interopDefault from '../_util/interopDefault'; import interopDefault from '../_util/interopDefault';
import InputIcon from './InputIcon'; import InputIcon from './InputIcon';
import { getDataAndAriaProps } from '../_util/util';
function formatValue(value, format) { function formatValue(value, format) {
return (value && value.format(format)) || ''; return (value && value.format(format)) || '';
@ -207,7 +208,12 @@ export default {
style: popupStyle, style: popupStyle,
}; };
return ( return (
<span class={classNames(className, pickerClass)} style={style} id={id}> <span
class={classNames(className, pickerClass)}
style={style}
id={id}
{...getDataAndAriaProps(props)}
>
<VcDatePicker {...vcDatePickerProps} vSlots={{ default: input, ...$slots }}></VcDatePicker> <VcDatePicker {...vcDatePickerProps} vSlots={{ default: input, ...$slots }}></VcDatePicker>
</span> </span>
); );

View File

@ -18,6 +18,7 @@ import {
} from '../_util/props-util'; } from '../_util/props-util';
import { cloneElement } from '../_util/vnode'; import { cloneElement } from '../_util/vnode';
import { formatDate } from './utils'; import { formatDate } from './utils';
import { getDataAndAriaProps } from '../_util/util';
// export const PickerProps = { // export const PickerProps = {
// value?: moment.Moment; // value?: moment.Moment;
@ -244,6 +245,7 @@ export default function createPicker(TheCalendar, props) {
// tabindex={props.disabled ? -1 : 0} // tabindex={props.disabled ? -1 : 0}
// onFocus={focus} // onFocus={focus}
// onBlur={blur} // onBlur={blur}
{...getDataAndAriaProps(this.$attrs)}
onMouseenter={this.onMouseEnter} onMouseenter={this.onMouseEnter}
onMouseleave={this.onMouseLeave} onMouseleave={this.onMouseLeave}
> >

View File

@ -213,7 +213,7 @@ const Drawer = {
const handler = getComponent(this, 'handle') || false; const handler = getComponent(this, 'handle') || false;
const getPrefixCls = this.configProvider.getPrefixCls; const getPrefixCls = this.configProvider.getPrefixCls;
const prefixCls = getPrefixCls('drawer', customizePrefixCls); const prefixCls = getPrefixCls('drawer', customizePrefixCls);
const { class: className } = this.$attrs;
const vcDrawerProps = { const vcDrawerProps = {
...this.$attrs, ...this.$attrs,
...omit(rest, [ ...omit(rest, [
@ -241,6 +241,7 @@ const Drawer = {
showMask: mask, showMask: mask,
placement, placement,
class: classnames({ class: classnames({
[className]: !!className,
[wrapClassName]: !!wrapClassName, [wrapClassName]: !!wrapClassName,
[haveMask]: !!haveMask, [haveMask]: !!haveMask,
}), }),

View File

@ -9,6 +9,7 @@ import {
import { cloneElement } from '../../_util/vnode'; import { cloneElement } from '../../_util/vnode';
import openAnimationFactory from './openAnimationFactory'; import openAnimationFactory from './openAnimationFactory';
import { collapseProps } from './commonProps'; import { collapseProps } from './commonProps';
import { getDataAndAriaProps } from '../../_util/util';
function _toArray(activeKey) { function _toArray(activeKey) {
let currentActiveKey = activeKey; let currentActiveKey = activeKey;
@ -131,7 +132,12 @@ export default {
[className]: className, [className]: className,
}; };
return ( return (
<div class={collapseClassName} style={style} role={accordion ? 'tablist' : null}> <div
class={collapseClassName}
{...getDataAndAriaProps(this.$attrs)}
style={style}
role={accordion ? 'tablist' : null}
>
{this.getItems()} {this.getItems()}
</div> </div>
); );

View File

@ -381,7 +381,7 @@ const Drawer = {
keyboard, keyboard,
maskClosable, maskClosable,
} = this.$props; } = this.$props;
const { class: cls, style } = this.$attrs; const { class: cls, style, ...restAttrs } = this.$attrs;
const children = getSlot(this); const children = getSlot(this);
const wrapperClassname = classnames(prefixCls, { const wrapperClassname = classnames(prefixCls, {
[`${prefixCls}-${placement}`]: true, [`${prefixCls}-${placement}`]: true,
@ -424,6 +424,7 @@ const Drawer = {
}); });
} }
const domContProps = { const domContProps = {
...restAttrs,
class: wrapperClassname, class: wrapperClassname,
onTransitionend: this.onWrapperTransitionEnd, onTransitionend: this.onWrapperTransitionEnd,
onKeydown: open && keyboard ? this.onKeyDown : noop, onKeydown: open && keyboard ? this.onKeyDown : noop,

View File

@ -48,6 +48,7 @@ import { SelectPropTypes } from './PropTypes';
import contains from '../vc-util/Dom/contains'; import contains from '../vc-util/Dom/contains';
import { isIE, isEdge } from '../_util/env'; import { isIE, isEdge } from '../_util/env';
import isValid from '../_util/isValid'; import isValid from '../_util/isValid';
import { getDataAndAriaProps } from '../_util/util';
const SELECT_EMPTY_VALUE_KEY = 'RC_SELECT_EMPTY_VALUE_KEY'; const SELECT_EMPTY_VALUE_KEY = 'RC_SELECT_EMPTY_VALUE_KEY';
@ -1580,6 +1581,7 @@ const Select = {
ariaId={this.$data._ariaId} ariaId={this.$data._ariaId}
> >
<div <div
{...getDataAndAriaProps(this.$attrs)}
ref={chaining(this.saveRootRef, this.saveSelectionRef)} ref={chaining(this.saveRootRef, this.saveSelectionRef)}
style={style} style={style}
class={classnames(rootCls)} class={classnames(rootCls)}

View File

@ -1,19 +1,60 @@
<template> <template>
<div> <div>
<demo /> <a-affix class="red"></a-affix>
<a-alert class="red"></a-alert>
<a-anchor class="red">
<a-anchor-link class="red" href="#components-anchor-demo-basic" title="Basic demo" />
</a-anchor>
<a-auto-complete :dataSource="[]" class="red"></a-auto-complete>
<a-avatar class="red"></a-avatar>
<a-back-top class="red">jjj</a-back-top>
<a-badge class="red"></a-badge>
<a-breadcrumb class="red">
<a-breadcrumb-item class="red">Home</a-breadcrumb-item>
</a-breadcrumb>
<a-button class="red"></a-button>
<a-calendar class="red"></a-calendar>
<a-card class="red"></a-card>
<a-carousel class="red">
<div>
<h3>1</h3>
</div>
</a-carousel>
<a-checkbox class="red">Checkbox</a-checkbox>
<a-checkbox-group class="red"></a-checkbox-group>
<a-collapse class="red">
<a-collapse-panel class="red" key="1" header="This is panel header 1">
<p>{{ text }}</p>
</a-collapse-panel>
<a-collapse-panel key="2" header="This is panel header 2" :disabled="false">
<p>{{ text }}</p>
</a-collapse-panel>
<a-collapse-panel key="3" header="This is panel header 3" disabled>
<p>{{ text }}</p>
</a-collapse-panel>
</a-collapse>
<a-date-picker class="red"></a-date-picker>
<br />
<a-month-picker class="red" placeholder="Select month" />
<br />
<a-range-picker class="red" />
<br />
<a-week-picker class="red" placeholder="Select week" />
<a-descriptions title="User Info" class="red">
<a-descriptions-item label="Address" class="red"
>No. 18, Wantang Road, Xihu District, Hangzhou, Zhejiang, China</a-descriptions-item
>
</a-descriptions>
<a-drawer class="red" style="margin-top: 10px"></a-drawer>>
<a-dropdown class="red">
<a>ssss</a>
</a-dropdown>
<a-dropdown-button class="red"></a-dropdown-button>
</div> </div>
</template> </template>
<script> <style scoped>
import demo from '../antdv-demo/docs/select/demo/custom-dropdown-menu'; .red {
export default { color: red;
components: { }</style
demo, >>
},
data() {
return {
visible: true,
current: ['mail'],
};
},
};
</script>