Skip to content

Commit 4d3134b

Browse files
committed
feat: forbid inheritAttrs
1 parent 322bf3f commit 4d3134b

File tree

3 files changed

+23
-5
lines changed

3 files changed

+23
-5
lines changed

components/auto-complete/index.jsx

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import Select, { AbstractSelectProps, SelectValue } from '../select'
44
import Input from '../input'
55
import InputElement from './InputElement'
66
import PropTypes from '../_util/vue-types'
7-
import { getComponentFromProp, getOptionProps, filterEmpty } from '../_util/props-util'
7+
import { getComponentFromProp, getOptionProps, filterEmpty, isValidElement, getEvents, getStyle, getClass } from '../_util/props-util'
88

99
const DataSourceItemObject = PropTypes.shape({
1010
value: String,
@@ -24,7 +24,7 @@ const AutoCompleteProps = {
2424
...AbstractSelectProps,
2525
value: SelectValue,
2626
defaultValue: SelectValue,
27-
dataSource: PropTypes.arrayOf(DataSourceItemType),
27+
dataSource: PropTypes.array,
2828
optionLabelProp: String,
2929
dropdownMatchSelectWidth: PropTypes.bool,
3030
// onChange?: (value: SelectValue) => void;
@@ -57,6 +57,13 @@ export default {
5757
const { $slots } = this
5858
const children = filterEmpty($slots.default)
5959
const element = children.length ? children[0] : <Input />
60+
console.log(element)
61+
const eleProps = {
62+
props: getOptionProps(element),
63+
on: getEvents(element),
64+
style: getStyle(element),
65+
class: getClass(element),
66+
}
6067
return (
6168
<InputElement>{element}</InputElement>
6269
)
@@ -97,6 +104,9 @@ export default {
97104
options = childArray
98105
} else {
99106
options = dataSource ? dataSource.map((item) => {
107+
if (isValidElement(item)) {
108+
return item
109+
}
100110
switch (typeof item) {
101111
case 'string':
102112
return <Option key={item}>{item}</Option>

components/cascader/index.jsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import omit from 'omit.js'
77
import KeyCode from '../_util/KeyCode'
88
import Input from '../input'
99
import Icon from '../icon'
10-
import { hasProp, filterEmpty, getOptionProps } from '../_util/props-util'
10+
import { hasProp, filterEmpty, getOptionProps, getStyle, getClass, getAttrs } from '../_util/props-util'
1111
import BaseMixin from '../_util/BaseMixin'
1212

1313
const CascaderOptionType = PropTypes.shape({
@@ -83,6 +83,7 @@ function defaultSortFilteredOption (a, b, inputValue) {
8383
const defaultDisplayRender = ({ labels }) => labels.join(' / ')
8484

8585
export default {
86+
inheritAttrs: false,
8687
name: 'ACascader',
8788
mixins: [BaseMixin],
8889
props: CascaderProps,
@@ -280,6 +281,7 @@ export default {
280281
[`${prefixCls}-picker-arrow-expand`]: sPopupVisible,
281282
})
282283
const pickerCls = classNames(
284+
getClass(this),
283285
`${prefixCls}-picker`, {
284286
[`${prefixCls}-picker-with-value`]: inputValue,
285287
[`${prefixCls}-picker-disabled`]: disabled,
@@ -345,11 +347,13 @@ export default {
345347
keydown: this.handleKeyDown,
346348
change: showSearch ? this.handleInputChange : noop,
347349
},
350+
attrs: getAttrs(this),
348351
}
349352
const children = filterEmpty($slots.default)
350353
const input = children.length ? children : (
351354
<span
352355
class={pickerCls}
356+
style={getStyle(this)}
353357
>
354358
{ showSearch ? <span class={`${prefixCls}-picker-label`}>
355359
{this.getLabel()}

components/vc-select/Select.jsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import classes from 'component-classes'
66
import { Item as MenuItem, ItemGroup as MenuItemGroup } from '../vc-menu'
77
import warning from 'warning'
88
import Option from './Option'
9-
import { hasProp, getSlotOptions, getPropsData, getValueByProp as getValue, getComponentFromProp, getEvents, getClass } from '../_util/props-util'
9+
import { hasProp, getSlotOptions, getPropsData, getValueByProp as getValue, getComponentFromProp, getEvents, getClass, getStyle, getAttrs } from '../_util/props-util'
1010
import getTransitionProps from '../_util/getTransitionProps'
1111
import { cloneElement } from '../_util/vnode'
1212
import BaseMixin from '../_util/BaseMixin'
@@ -45,6 +45,7 @@ function chaining (...fns) {
4545
}
4646
}
4747
export default {
48+
inheritAttrs: false,
4849
name: 'Select',
4950
mixins: [BaseMixin],
5051
props: {
@@ -706,9 +707,10 @@ export default {
706707
},
707708
_getInputElement () {
708709
const props = this.$props
710+
const attrs = getAttrs(this)
709711
const inputElement = props.getInputElement
710712
? props.getInputElement()
711-
: <input id={props.id} autoComplete='off'/>
713+
: <input id={attrs.id} autoComplete='off'/>
712714
const inputCls = classnames(getClass(inputElement), {
713715
[`${props.prefixCls}-search__field`]: true,
714716
})
@@ -1501,6 +1503,7 @@ export default {
15011503
selectionProps.attrs.tabIndex = props.disabled ? -1 : 0
15021504
}
15031505
const rootCls = {
1506+
...getClass(this),
15041507
[prefixCls]: true,
15051508
[`${prefixCls}-open`]: openStatus,
15061509
[`${prefixCls}-focused`]: openStatus || !!this._focused,
@@ -1542,6 +1545,7 @@ export default {
15421545
>
15431546
<div
15441547
ref='rootRef'
1548+
style={getStyle(this)}
15451549
class={classnames(rootCls)}
15461550
// tabindex='-1'
15471551
// onBlur={this.onOuterBlur}

0 commit comments

Comments
 (0)