add hasProp
parent
7d52bd4852
commit
68f1bc65fc
|
@ -0,0 +1,5 @@
|
|||
export default (instance, prop) => {
|
||||
const $options = instance.$options || {}
|
||||
const propsData = $options.propsData || {}
|
||||
return prop in propsData
|
||||
}
|
|
@ -13,6 +13,7 @@
|
|||
</label>
|
||||
</template>
|
||||
<script>
|
||||
import hasProp from '../_util/hasProp'
|
||||
export default {
|
||||
name: 'Checkbox',
|
||||
props: {
|
||||
|
@ -42,7 +43,7 @@ export default {
|
|||
}
|
||||
return {
|
||||
stateChecked: stateChecked === undefined
|
||||
? checked === undefined ? defaultChecked : checked
|
||||
? !hasProp(this, 'checked') ? defaultChecked : checked
|
||||
: stateChecked,
|
||||
}
|
||||
},
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
</template>
|
||||
<script>
|
||||
import Checkbox from './Checkbox.vue'
|
||||
import hasProp from '../_util/hasProp'
|
||||
export default {
|
||||
name: 'CheckboxGroup',
|
||||
props: {
|
||||
|
@ -60,7 +61,7 @@ export default {
|
|||
handleChange (event) {
|
||||
const target = event.target
|
||||
const { value: targetValue, checked } = target
|
||||
const { stateValue, value } = this
|
||||
const { stateValue } = this
|
||||
let newVal = []
|
||||
if (checked) {
|
||||
newVal = [...stateValue, targetValue]
|
||||
|
@ -70,7 +71,7 @@ export default {
|
|||
index >= 0 && newVal.splice(index, 1)
|
||||
}
|
||||
newVal = [...new Set(newVal)]
|
||||
if (value === undefined) {
|
||||
if (!hasProp(this, 'value')) {
|
||||
this.stateValue = newVal
|
||||
}
|
||||
this.$emit('input', newVal)
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
import TextArea from './TextArea'
|
||||
import omit from 'omit.js'
|
||||
import inputProps from './inputProps'
|
||||
import hasProp from '../_util/hasProp'
|
||||
|
||||
function fixControlledValue (value) {
|
||||
if (typeof value === 'undefined' || value === null) {
|
||||
|
@ -22,7 +23,7 @@ export default {
|
|||
data () {
|
||||
const { value, defaultValue } = this.$props
|
||||
return {
|
||||
stateValue: fixControlledValue(value === undefined ? defaultValue : value),
|
||||
stateValue: fixControlledValue(!hasProp(this, 'value') ? defaultValue : value),
|
||||
}
|
||||
},
|
||||
computed: {
|
||||
|
@ -40,8 +41,7 @@ export default {
|
|||
this.$emit('keydown', e)
|
||||
},
|
||||
handleChange (e) {
|
||||
const { value } = this.$props
|
||||
if (value === undefined) {
|
||||
if (!hasProp(this, 'value')) {
|
||||
this.stateValue = e.target.value
|
||||
} else {
|
||||
this.$forceUpdate()
|
||||
|
|
|
@ -1,9 +1,8 @@
|
|||
<script>
|
||||
import omit from 'omit.js'
|
||||
|
||||
import inputProps from './inputProps'
|
||||
|
||||
import calculateNodeHeight from './calculateNodeHeight'
|
||||
import hasProp from '../_util/hasProp'
|
||||
|
||||
function onNextFrame (cb) {
|
||||
if (window.requestAnimationFrame) {
|
||||
|
@ -39,7 +38,7 @@ export default {
|
|||
data () {
|
||||
const { value, defaultValue } = this.$props
|
||||
return {
|
||||
stateValue: fixControlledValue(value === undefined ? defaultValue : value),
|
||||
stateValue: fixControlledValue(!hasProp(this, 'value') ? defaultValue : value),
|
||||
nextFrameActionId: undefined,
|
||||
textareaStyles: {},
|
||||
}
|
||||
|
@ -85,8 +84,7 @@ export default {
|
|||
},
|
||||
|
||||
handleTextareaChange (e) {
|
||||
const { value } = this.$props
|
||||
if (value === undefined) {
|
||||
if (!hasProp(this, 'value')) {
|
||||
this.stateValue = e.target.value
|
||||
this.$nextTick(() => {
|
||||
this.resizeTextarea()
|
||||
|
|
|
@ -1,11 +1,10 @@
|
|||
<script>
|
||||
import PropTypes from 'vue-types'
|
||||
import PropTypes from '../../_util/vue-types'
|
||||
import MenuMixin from './MenuMixin'
|
||||
import StateMixin from '../../_util/StateMixin'
|
||||
|
||||
const Menu = {
|
||||
name: 'Menu',
|
||||
|
||||
props: {
|
||||
defaultSelectedKeys: PropTypes.arrayOf(PropTypes.string).def([]),
|
||||
selectedKeys: PropTypes.arrayOf(PropTypes.string),
|
||||
|
@ -38,16 +37,20 @@ const Menu = {
|
|||
isRootMenu: true,
|
||||
}
|
||||
},
|
||||
|
||||
componentWillReceiveProps (nextProps) {
|
||||
const props = {}
|
||||
if ('selectedKeys' in nextProps) {
|
||||
props.selectedKeys = nextProps.selectedKeys || []
|
||||
}
|
||||
if ('openKeys' in nextProps) {
|
||||
props.openKeys = nextProps.openKeys || []
|
||||
}
|
||||
this.setState(props)
|
||||
watch: {
|
||||
'$props': {
|
||||
handler: function (nextProps) {
|
||||
const props = {}
|
||||
if (nextProps.selectedKeys === undefined) {
|
||||
props.selectedKeys = nextProps.selectedKeys || []
|
||||
}
|
||||
if (nextProps.openKeys === undefined) {
|
||||
props.openKeys = nextProps.openKeys || []
|
||||
}
|
||||
this.setState(props)
|
||||
},
|
||||
deep: true,
|
||||
},
|
||||
},
|
||||
methods: {
|
||||
onDestroy (key) {
|
||||
|
|
|
@ -13,6 +13,7 @@
|
|||
</label>
|
||||
</template>
|
||||
<script>
|
||||
import hasProp from '../_util/hasProp'
|
||||
export default {
|
||||
name: 'Radio',
|
||||
props: {
|
||||
|
@ -41,7 +42,7 @@ export default {
|
|||
}
|
||||
return {
|
||||
stateChecked: stateChecked === undefined
|
||||
? checked === undefined ? defaultChecked : checked
|
||||
? !hasProp(this, 'checked') ? defaultChecked : checked
|
||||
: stateChecked,
|
||||
}
|
||||
},
|
||||
|
@ -70,8 +71,8 @@ export default {
|
|||
handleChange (event) {
|
||||
const targetChecked = event.target.checked
|
||||
this.$emit('input', targetChecked)
|
||||
const { name, value, checked, radioGroupContext, stateChecked } = this
|
||||
if ((checked === undefined && !radioGroupContext) || (radioGroupContext && radioGroupContext.value === undefined)) {
|
||||
const { name, value, radioGroupContext, stateChecked } = this
|
||||
if ((!hasProp(this, 'checked') && !radioGroupContext) || (radioGroupContext && radioGroupContext.value === undefined)) {
|
||||
this.stateChecked = targetChecked
|
||||
}
|
||||
const target = {
|
||||
|
|
|
@ -3,6 +3,7 @@ import Star from './Star.vue'
|
|||
import Icon from '../icon'
|
||||
import { getOffsetLeft } from './util'
|
||||
import { cloneVNodes } from '../_util/vnode'
|
||||
import hasProp from '../_util/hasProp'
|
||||
|
||||
export default {
|
||||
name: 'Rate',
|
||||
|
@ -35,7 +36,7 @@ export default {
|
|||
},
|
||||
data () {
|
||||
const { value, defaultValue } = this
|
||||
const reValue = value === undefined ? defaultValue : value
|
||||
const reValue = !hasProp(this, 'value') ? defaultValue : value
|
||||
return {
|
||||
hoverValue: undefined,
|
||||
stateValue: reValue,
|
||||
|
@ -59,7 +60,10 @@ export default {
|
|||
methods: {
|
||||
onClick (event, index) {
|
||||
const value = this.getStarValue(index, event.pageX)
|
||||
this.stateValue = value
|
||||
if (!hasProp(this, 'value')) {
|
||||
this.stateValue = value
|
||||
}
|
||||
|
||||
this.onMouseLeave()
|
||||
this.$emit('input', value)
|
||||
this.$emit('change', value)
|
||||
|
|
|
@ -3,6 +3,7 @@ import Icon from '../icon'
|
|||
import KeyCode from './KeyCode'
|
||||
import TabContent from './TabContent'
|
||||
import ScrollableInkTabBar from './ScrollableInkTabBar'
|
||||
import hasProp from '../_util/hasProp'
|
||||
function getDefaultActiveKey (t) {
|
||||
let activeKey
|
||||
t.$slots.default && t.$slots.default.forEach(({ componentOptions = {}, key: tabKey }) => {
|
||||
|
@ -108,7 +109,7 @@ export default {
|
|||
|
||||
setActiveKey (activeKey) {
|
||||
if (this.stateActiveKey !== activeKey) {
|
||||
if (!this.activeKey) {
|
||||
if (!hasProp(this, 'activeKey')) {
|
||||
this.stateActiveKey = activeKey
|
||||
}
|
||||
this.onChange(activeKey)
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
<script>
|
||||
import Tabs from './Tabs'
|
||||
import isFlexSupported from '../_util/isFlexSupported'
|
||||
import hasProp from '../_util/hasProp'
|
||||
export default {
|
||||
props: {
|
||||
prefixCls: { type: String, default: 'ant-tabs' },
|
||||
|
@ -135,7 +136,6 @@ export default {
|
|||
tabBarProps: tabBarProps,
|
||||
tabContentProps: tabContentProps,
|
||||
destroyInactiveTabPane,
|
||||
activeKey,
|
||||
defaultActiveKey,
|
||||
type,
|
||||
onTabClick: this.onTabClick,
|
||||
|
@ -146,6 +146,9 @@ export default {
|
|||
},
|
||||
},
|
||||
}
|
||||
if (hasProp(this, 'activeKey')) {
|
||||
tabsProps.props.activeKey = activeKey
|
||||
}
|
||||
return (
|
||||
<Tabs
|
||||
class={cls}
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
<script>
|
||||
import PropTypes from '../_util/vue-types'
|
||||
import contains from '../_util/Dom/contains'
|
||||
import hasProp from '../_util/hasProp'
|
||||
import addEventListener from '../_util/Dom/addEventListener'
|
||||
import warning from '../_util/warning'
|
||||
import Popup from './Popup'
|
||||
|
@ -22,7 +23,6 @@ const ALL_HANDLERS = ['click', 'mousedown', 'touchStart', 'mouseenter',
|
|||
export default {
|
||||
name: 'Trigger',
|
||||
props: {
|
||||
children: PropTypes.any,
|
||||
action: PropTypes.oneOfType([PropTypes.string, PropTypes.arrayOf(PropTypes.string)]).def([]),
|
||||
showAction: PropTypes.any.def([]),
|
||||
hideAction: PropTypes.any.def([]),
|
||||
|
@ -66,7 +66,7 @@ export default {
|
|||
data () {
|
||||
const props = this.$props
|
||||
let popupVisible
|
||||
if (props.popupVisible === undefined) {
|
||||
if (hasProp(this, 'popupVisible')) {
|
||||
popupVisible = !!props.popupVisible
|
||||
} else {
|
||||
popupVisible = !!props.defaultPopupVisible
|
||||
|
@ -352,7 +352,7 @@ export default {
|
|||
setPopupVisible (sPopupVisible) {
|
||||
this.clearDelayTimer()
|
||||
if (this.$data.sPopupVisible !== sPopupVisible) {
|
||||
if (this.$props.popupVisible === undefined) {
|
||||
if (!hasProp(this, 'popupVisible')) {
|
||||
this.setState({
|
||||
sPopupVisible,
|
||||
})
|
||||
|
|
Loading…
Reference in New Issue