Skip to content

Commit 6f15a47

Browse files
committed
feat: update vc-menu vc-select
1 parent ac88e49 commit 6f15a47

File tree

7 files changed

+34
-13
lines changed

7 files changed

+34
-13
lines changed

components/vc-menu/DOMWrap.jsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ const canUseDOM = !!(
1313
)
1414

1515
const MENUITEM_OVERFLOWED_CLASSNAME = 'menuitem-overflowed'
16+
const FLOAT_PRECISION_ADJUST = 0.5
1617

1718
// Fix ssr
1819
if (canUseDOM) {
@@ -215,7 +216,10 @@ const DOMWrap = {
215216
// index for last visible child in horizontal mode
216217
let lastVisibleIndex
217218

218-
if (this.originalTotalWidth > width) {
219+
// float number comparison could be problematic
220+
// e.g. 0.1 + 0.2 > 0.3 =====> true
221+
// thus using FLOAT_PRECISION_ADJUST as buffer to help the situation
222+
if (this.originalTotalWidth > width + FLOAT_PRECISION_ADJUST) {
219223
lastVisibleIndex = -1
220224

221225
this.menuItemSizes.forEach(liWidth => {

components/vc-menu/SubPopupMenu.jsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { connect } from '../_util/store'
44
import BaseMixin from '../_util/BaseMixin'
55
import KeyCode from '../_util/KeyCode'
66
import classNames from 'classnames'
7-
import { getKeyFromChildrenIndex, loopMenuItem, noop } from './util'
7+
import { getKeyFromChildrenIndex, loopMenuItem, noop, isMobileDevice } from './util'
88
import DOMWrap from './DOMWrap'
99
import { cloneElement } from '../_util/vnode'
1010
import { initDefaultProps, getOptionProps, getPropsData, getEvents, getComponentFromProp } from '../_util/props-util'
@@ -324,7 +324,8 @@ const SubPopupMenu = {
324324
select: this.onSelect,
325325
},
326326
}
327-
if (props.mode === 'inline') {
327+
// ref: https://github.com/ant-design/ant-design/issues/13943
328+
if (props.mode === 'inline' || isMobileDevice()) {
328329
newChildProps.props.triggerSubMenuAction = 'click'
329330
}
330331
return cloneElement(child, newChildProps)

components/vc-menu/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// based on rc-menu 7.4.20
1+
// based on rc-menu 7.4.21
22
import Menu from './Menu'
33
import SubMenu from './SubMenu'
44
import MenuItem, { menuItemProps } from './MenuItem'

components/vc-menu/util.js

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
const isMobile = require('ismobilejs')
2+
13
export function noop () {
24
}
35

@@ -113,14 +115,27 @@ export const menuAllProps = {
113115
],
114116
}
115117

116-
export const getWidth = (elem) => (
117-
elem &&
118-
typeof elem.getBoundingClientRect === 'function' &&
119-
elem.getBoundingClientRect().width
120-
) || 0
118+
// ref: https://github.com/ant-design/ant-design/issues/14007
119+
// ref: https://bugs.chromium.org/p/chromium/issues/detail?id=360889
120+
// getBoundingClientRect return the full precision value, which is
121+
// not the same behavior as on chrome. Set the precision to 6 to
122+
// unify their behavior
123+
export const getWidth = (elem) => {
124+
let width = elem &&
125+
typeof elem.getBoundingClientRect === 'function' &&
126+
elem.getBoundingClientRect().width
127+
if (width) {
128+
width = +width.toFixed(6)
129+
}
130+
return width || 0
131+
}
121132

122133
export const setStyle = (elem, styleProperty, value) => {
123134
if (elem && typeof elem.style === 'object') {
124135
elem.style[styleProperty] = value
125136
}
126137
}
138+
139+
export const isMobileDevice = () => {
140+
return isMobile.any
141+
}

components/vc-select/Select.jsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,6 @@ const Select = {
103103
this.saveSelectTriggerRef = saveRef(this, 'selectTriggerRef')
104104
this.saveRootRef = saveRef(this, 'rootRef')
105105
this.saveSelectionRef = saveRef(this, 'selectionRef')
106-
this.ariaId = generateUUID()
107106
this._focused = false
108107
this._mouseDown = false
109108
this._options = []
@@ -127,6 +126,7 @@ const Select = {
127126
_backfillValue: '',
128127
// a flag for aviod redundant getOptionsInfoFromProps call
129128
_skipBuildOptionsInfo: true,
129+
_ariaId: generateUUID(),
130130
}
131131
return {
132132
...state,
@@ -1497,7 +1497,7 @@ const Select = {
14971497
'aria-autocomplete': 'list',
14981498
'aria-haspopup': 'true',
14991499
'aria-expanded': realOpen,
1500-
'aria-controls': this.ariaId,
1500+
'aria-controls': this.$data._ariaId,
15011501
},
15021502
on: {
15031503
click: this.selectionRefClick,
@@ -1562,7 +1562,7 @@ const Select = {
15621562
value: this.saveSelectTriggerRef,
15631563
}] }}
15641564
dropdownRender={props.dropdownRender}
1565-
ariaId={this.ariaId}
1565+
ariaId={this.$data._ariaId}
15661566
>
15671567
<div
15681568
{...{ directives: [{

components/vc-select/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// based on vc-select 8.6.9
1+
// based on vc-select 8.7.0
22
import ProxySelect, { Select } from './Select'
33
import Option from './Option'
44
import { SelectPropTypes } from './PropTypes'

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,7 @@
173173
"enquire.js": "^2.1.6",
174174
"intersperse": "^1.0.0",
175175
"is-negative-zero": "^2.0.0",
176+
"ismobilejs": "^0.5.1",
176177
"json2mq": "^0.2.0",
177178
"lodash": "^4.17.5",
178179
"moment": "^2.21.0",

0 commit comments

Comments
 (0)