From 4bdb241aa674b50fafa29b3b98e291643f2a06cc Mon Sep 17 00:00:00 2001 From: tanjinzhou <415800467@qq.com> Date: Thu, 20 Aug 2020 17:56:49 +0800 Subject: [PATCH] fix: some component not support css scoped --- antdv-demo | 2 +- components/_util/util.js | 9 ++++ components/anchor/Anchor.jsx | 7 +-- components/anchor/AnchorLink.jsx | 3 +- components/carousel/index.jsx | 14 ++--- components/date-picker/RangePicker.jsx | 2 + components/date-picker/WeekPicker.jsx | 8 ++- components/date-picker/createPicker.js | 2 + components/drawer/index.jsx | 3 +- components/vc-collapse/src/Collapse.jsx | 8 ++- components/vc-drawer/src/Drawer.js | 3 +- components/vc-select/Select.jsx | 2 + examples/App.vue | 71 +++++++++++++++++++------ 13 files changed, 102 insertions(+), 32 deletions(-) diff --git a/antdv-demo b/antdv-demo index 38ec9e4d59..31e7b308ad 160000 --- a/antdv-demo +++ b/antdv-demo @@ -1 +1 @@ -Subproject commit 38ec9e4d590312ac56c01203ae13453bdf36a0c7 +Subproject commit 31e7b308adb6eabb97c003fbc7883e4d00c8f764 diff --git a/components/_util/util.js b/components/_util/util.js index 18252b386a..8c8e7ced53 100644 --- a/components/_util/util.js +++ b/components/_util/util.js @@ -48,4 +48,13 @@ function resolvePropValue(options, props, key, 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 }; diff --git a/components/anchor/Anchor.jsx b/components/anchor/Anchor.jsx index b24a6300c4..9150d5f675 100644 --- a/components/anchor/Anchor.jsx +++ b/components/anchor/Anchor.jsx @@ -272,7 +272,6 @@ export default { $slots, getContainer, } = this; - const getPrefixCls = this.configProvider.getPrefixCls; const prefixCls = getPrefixCls('anchor', customizePrefixCls); this._sPrefixCls = prefixCls; @@ -281,7 +280,7 @@ export default { visible: activeLink, }); - const wrapperClass = classNames(this.$attrs.class, this.wrapperClass, `${prefixCls}-wrapper`); + const wrapperClass = classNames(this.wrapperClass, `${prefixCls}-wrapper`); const anchorClass = classNames(prefixCls, { fixed: !affix && !showInkInFixed, @@ -290,9 +289,7 @@ export default { const wrapperStyle = { maxHeight: offsetTop ? `calc(100vh - ${offsetTop}px)` : '100vh', ...this.wrapperStyle, - ...this.$attrs.style, }; - const anchorContent = (
@@ -307,7 +304,7 @@ export default { return !affix ? ( anchorContent ) : ( - + {anchorContent} ); diff --git a/components/anchor/AnchorLink.jsx b/components/anchor/AnchorLink.jsx index f80ba5f9b8..40579b2171 100644 --- a/components/anchor/AnchorLink.jsx +++ b/components/anchor/AnchorLink.jsx @@ -23,6 +23,7 @@ export default { registerLink: noop, unregisterLink: noop, scrollTo: noop, + $data: {}, }), antAnchorContext: inject('antAnchorContext', {}), configProvider: inject('configProvider', ConfigConsumerProps), @@ -62,7 +63,7 @@ export default { const prefixCls = getPrefixCls('anchor', customizePrefixCls); const title = getComponent(this, 'title'); - const active = this.antAnchor.activeLink === href; + const active = this.antAnchor.$data.activeLink === href; const wrapperClassName = classNames(`${prefixCls}-link`, { [`${prefixCls}-link-active`]: active, }); diff --git a/components/carousel/index.jsx b/components/carousel/index.jsx index dbd93ef745..22b87d849c 100644 --- a/components/carousel/index.jsx +++ b/components/carousel/index.jsx @@ -153,7 +153,7 @@ const Carousel = { if (props.effect === 'fade') { props.fade = true; } - + const { class: cls, style, ...restAttrs } = this.$attrs; const getPrefixCls = this.configProvider.getPrefixCls; let className = getPrefixCls('carousel', props.prefixCls); const dotsClass = 'slick-dots'; @@ -162,17 +162,19 @@ const Carousel = { props.dotsClass = classNames(`${dotsClass}`, `${dotsClass}-${dotPosition || 'bottom'}`, { [`${props.dotsClass}`]: !!props.dotsClass, }); - if (props.vertical) { - className = `${className} ${className}-vertical`; - } + className = classNames({ + [cls]: !!cls, + [className]: !!className, + [`${className}-vertical`]: props.vertical, + }); const SlickCarouselProps = { ...props, - ...this.$attrs, + ...restAttrs, nextArrow: getComponent(this, 'nextArrow'), prevArrow: getComponent(this, 'prevArrow'), }; return ( -
+
); diff --git a/components/date-picker/RangePicker.jsx b/components/date-picker/RangePicker.jsx index a26892fe45..e332f899aa 100644 --- a/components/date-picker/RangePicker.jsx +++ b/components/date-picker/RangePicker.jsx @@ -13,6 +13,7 @@ import { hasProp, getOptionProps, initDefaultProps, getComponent } from '../_uti import BaseMixin from '../_util/BaseMixin'; import { formatDate } from './utils'; import InputIcon from './InputIcon'; +import { getDataAndAriaProps } from '../_util/util'; function getShowDateFromValue(value, mode) { const [start, end] = value; @@ -413,6 +414,7 @@ export default { onBlur={onBlur} onMouseenter={this.onMouseEnter} onMouseleave={this.onMouseLeave} + {...getDataAndAriaProps(props)} > diff --git a/components/date-picker/WeekPicker.jsx b/components/date-picker/WeekPicker.jsx index 04f768614b..b552fae007 100644 --- a/components/date-picker/WeekPicker.jsx +++ b/components/date-picker/WeekPicker.jsx @@ -10,6 +10,7 @@ import BaseMixin from '../_util/BaseMixin'; import { WeekPickerProps } from './interface'; import interopDefault from '../_util/interopDefault'; import InputIcon from './InputIcon'; +import { getDataAndAriaProps } from '../_util/util'; function formatValue(value, format) { return (value && value.format(format)) || ''; @@ -207,7 +208,12 @@ export default { style: popupStyle, }; return ( - + ); diff --git a/components/date-picker/createPicker.js b/components/date-picker/createPicker.js index 9aea18f828..cd12f4d9e5 100644 --- a/components/date-picker/createPicker.js +++ b/components/date-picker/createPicker.js @@ -18,6 +18,7 @@ import { } from '../_util/props-util'; import { cloneElement } from '../_util/vnode'; import { formatDate } from './utils'; +import { getDataAndAriaProps } from '../_util/util'; // export const PickerProps = { // value?: moment.Moment; @@ -244,6 +245,7 @@ export default function createPicker(TheCalendar, props) { // tabindex={props.disabled ? -1 : 0} // onFocus={focus} // onBlur={blur} + {...getDataAndAriaProps(this.$attrs)} onMouseenter={this.onMouseEnter} onMouseleave={this.onMouseLeave} > diff --git a/components/drawer/index.jsx b/components/drawer/index.jsx index 91113842a7..2584f95d87 100644 --- a/components/drawer/index.jsx +++ b/components/drawer/index.jsx @@ -213,7 +213,7 @@ const Drawer = { const handler = getComponent(this, 'handle') || false; const getPrefixCls = this.configProvider.getPrefixCls; const prefixCls = getPrefixCls('drawer', customizePrefixCls); - + const { class: className } = this.$attrs; const vcDrawerProps = { ...this.$attrs, ...omit(rest, [ @@ -241,6 +241,7 @@ const Drawer = { showMask: mask, placement, class: classnames({ + [className]: !!className, [wrapClassName]: !!wrapClassName, [haveMask]: !!haveMask, }), diff --git a/components/vc-collapse/src/Collapse.jsx b/components/vc-collapse/src/Collapse.jsx index 079e64190e..31609e0dde 100644 --- a/components/vc-collapse/src/Collapse.jsx +++ b/components/vc-collapse/src/Collapse.jsx @@ -9,6 +9,7 @@ import { import { cloneElement } from '../../_util/vnode'; import openAnimationFactory from './openAnimationFactory'; import { collapseProps } from './commonProps'; +import { getDataAndAriaProps } from '../../_util/util'; function _toArray(activeKey) { let currentActiveKey = activeKey; @@ -131,7 +132,12 @@ export default { [className]: className, }; return ( -
+
{this.getItems()}
); diff --git a/components/vc-drawer/src/Drawer.js b/components/vc-drawer/src/Drawer.js index fb4cae9acc..932310a5c3 100644 --- a/components/vc-drawer/src/Drawer.js +++ b/components/vc-drawer/src/Drawer.js @@ -381,7 +381,7 @@ const Drawer = { keyboard, maskClosable, } = this.$props; - const { class: cls, style } = this.$attrs; + const { class: cls, style, ...restAttrs } = this.$attrs; const children = getSlot(this); const wrapperClassname = classnames(prefixCls, { [`${prefixCls}-${placement}`]: true, @@ -424,6 +424,7 @@ const Drawer = { }); } const domContProps = { + ...restAttrs, class: wrapperClassname, onTransitionend: this.onWrapperTransitionEnd, onKeydown: open && keyboard ? this.onKeyDown : noop, diff --git a/components/vc-select/Select.jsx b/components/vc-select/Select.jsx index f7483e60d9..e536b705fe 100644 --- a/components/vc-select/Select.jsx +++ b/components/vc-select/Select.jsx @@ -48,6 +48,7 @@ import { SelectPropTypes } from './PropTypes'; import contains from '../vc-util/Dom/contains'; import { isIE, isEdge } from '../_util/env'; import isValid from '../_util/isValid'; +import { getDataAndAriaProps } from '../_util/util'; const SELECT_EMPTY_VALUE_KEY = 'RC_SELECT_EMPTY_VALUE_KEY'; @@ -1580,6 +1581,7 @@ const Select = { ariaId={this.$data._ariaId} >
- + + + + + + + + jjj + + + Home + + + + + +
+

1

+
+
+ Checkbox + + + +

{{ text }}

+
+ +

{{ text }}

+
+ +

{{ text }}

+
+
+ +
+ +
+ +
+ + + + No. 18, Wantang Road, Xihu District, Hangzhou, Zhejiang, China + + > + + ssss + +
- +>