Skip to content

Commit 19e4e27

Browse files
committed
feat: update vc-menu
1 parent 93bde3f commit 19e4e27

File tree

3 files changed

+95
-149
lines changed

3 files changed

+95
-149
lines changed

components/vc-select/DropdownMenu.jsx

+40-44
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,15 @@ import raf from 'raf';
22
import PropTypes from '../_util/vue-types';
33
import Menu from '../vc-menu';
44
import scrollIntoView from 'dom-scroll-into-view';
5-
import { getSelectKeys, preventDefaultEvent } from './util';
5+
import { getSelectKeys, preventDefaultEvent, saveRef } from './util';
66
import { cloneElement } from '../_util/vnode';
77
import BaseMixin from '../_util/BaseMixin';
8-
import { getSlotOptions, getComponentFromProp, getListeners } from '../_util/props-util';
8+
import { getSlotOptions, findDOMNode } from '../_util/props-util';
99

1010
export default {
1111
name: 'DropdownMenu',
1212
mixins: [BaseMixin],
13+
inheritAttrs: false,
1314
props: {
1415
ariaId: PropTypes.string,
1516
defaultActiveFirstOption: PropTypes.bool,
@@ -42,6 +43,7 @@ export default {
4243

4344
created() {
4445
this.rafInstance = null;
46+
this.saveMenuRef = saveRef(this, 'menuRef');
4547
this.lastInputValue = this.$props.inputValue;
4648
this.lastVisible = false;
4749
},
@@ -86,51 +88,36 @@ export default {
8688
// Delay to scroll since current frame item position is not ready when pre view is by filter
8789
// https://github.com/ant-design/ant-design/issues/11268#issuecomment-406634462
8890
this.rafInstance = raf(() => {
89-
scrollIntoView(itemComponent, this.$refs.menuRef.$el, scrollIntoViewOpts);
91+
scrollIntoView(itemComponent, findDOMNode(this.menuRef), scrollIntoViewOpts);
9092
});
9193
},
9294

9395
renderMenu() {
94-
const props = this.$props;
96+
const props = { ...this.$props, ...this.$attrs };
9597
const {
9698
menuItems,
99+
menuItemSelectedIcon,
97100
defaultActiveFirstOption,
98-
value,
99101
prefixCls,
100102
multiple,
103+
onMenuSelect,
101104
inputValue,
102-
firstActiveValue,
103-
dropdownMenuStyle,
104105
backfillValue,
106+
onMenuDeselect,
105107
visible,
106108
} = props;
107-
const menuItemSelectedIcon = getComponentFromProp(this, 'menuItemSelectedIcon');
108-
const { menuDeselect, menuSelect, popupScroll } = getListeners(this);
109+
const firstActiveValue = this.firstActiveValue;
109110
if (menuItems && menuItems.length) {
110-
const selectedKeys = getSelectKeys(menuItems, value);
111-
const menuProps = {
112-
props: {
113-
multiple,
114-
itemIcon: multiple ? menuItemSelectedIcon : null,
115-
selectedKeys,
116-
prefixCls: `${prefixCls}-menu`,
117-
},
118-
on: {},
119-
style: dropdownMenuStyle,
120-
ref: 'menuRef',
121-
attrs: {
122-
role: 'listbox',
123-
},
124-
};
125-
if (popupScroll) {
126-
menuProps.on.scroll = popupScroll;
127-
}
111+
const menuProps = {};
128112
if (multiple) {
129-
menuProps.on.deselect = menuDeselect;
130-
menuProps.on.select = menuSelect;
113+
menuProps.onDeselect = onMenuDeselect;
114+
menuProps.onSelect = onMenuSelect;
131115
} else {
132-
menuProps.on.click = menuSelect;
116+
menuProps.onClick = onMenuSelect;
133117
}
118+
119+
const value = this.value;
120+
const selectedKeys = getSelectKeys(menuItems, value);
134121
const activeKeyProps = {};
135122

136123
let defaultActiveFirst = defaultActiveFirstOption;
@@ -155,20 +142,16 @@ export default {
155142
) {
156143
foundFirst = true;
157144
return cloneElement(item, {
158-
directives: [
159-
{
160-
name: 'ant-ref',
161-
value: ref => {
162-
this.firstActiveItem = ref;
163-
},
164-
},
165-
],
145+
ref: ref => {
146+
this.firstActiveItem = ref;
147+
},
166148
});
167149
}
168150
return item;
169151
};
170152

171153
clonedMenuItems = menuItems.map(item => {
154+
debugger;
172155
if (getSlotOptions(item).isMenuItemGroup) {
173156
const children = item.componentOptions.children.map(clone);
174157
return cloneElement(item, { children });
@@ -187,15 +170,29 @@ export default {
187170
if (inputValue !== this.lastInputValue && (!lastValue || lastValue !== backfillValue)) {
188171
activeKeyProps.activeKey = '';
189172
}
190-
menuProps.props = { ...activeKeyProps, ...menuProps.props, defaultActiveFirst };
191-
return <Menu {...menuProps}>{clonedMenuItems}</Menu>;
173+
return (
174+
<Menu
175+
ref={this.saveMenuRef}
176+
style={this.dropdownMenuStyle}
177+
defaultActiveFirst={defaultActiveFirst}
178+
role="listbox"
179+
itemIcon={multiple ? menuItemSelectedIcon : null}
180+
{...activeKeyProps}
181+
multiple={multiple}
182+
{...menuProps}
183+
selectedKeys={selectedKeys}
184+
prefixCls={`${prefixCls}-menu`}
185+
>
186+
{clonedMenuItems}
187+
</Menu>
188+
);
192189
}
193190
return null;
194191
},
195192
},
196193
render() {
197194
const renderMenu = this.renderMenu();
198-
const { popupFocus, popupScroll } = getListeners(this);
195+
const { onPopupFocus, onPopupScroll } = this.$attrs;
199196
return renderMenu ? (
200197
<div
201198
style={{
@@ -204,10 +201,9 @@ export default {
204201
}}
205202
id={this.$props.ariaId}
206203
tabIndex="-1"
207-
onFocus={popupFocus}
204+
onFocus={onPopupFocus}
208205
onMousedown={preventDefaultEvent}
209-
onScroll={popupScroll}
210-
ref="menuContainer"
206+
onScroll={onPopupScroll}
211207
>
212208
{renderMenu}
213209
</div>

components/vc-select/Select.jsx

+6-12
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ const Select = {
8181
OptGroup,
8282
name: 'Select',
8383
mixins: [BaseMixin],
84+
inheritAttrs: false,
8485
props: {
8586
...SelectPropTypes,
8687
prefixCls: SelectPropTypes.prefixCls.def('rc-select'),
@@ -112,10 +113,10 @@ const Select = {
112113
// onDeselect: noop,
113114
// onInputKeydown: noop,
114115
},
115-
model: {
116-
prop: 'value',
117-
event: 'change',
118-
},
116+
// model: {
117+
// prop: 'value',
118+
// event: 'change',
119+
// },
119120
created() {
120121
this.saveInputRef = saveRef(this, 'inputRef');
121122
this.saveInputMirrorRef = saveRef(this, 'inputMirrorRef');
@@ -1667,14 +1668,7 @@ const Select = {
16671668
onMouseleave={mouseleave}
16681669
showAction={props.showAction}
16691670
menuItemSelectedIcon={getComponentFromProp(this, 'menuItemSelectedIcon')}
1670-
{...{
1671-
directives: [
1672-
{
1673-
name: 'ant-ref',
1674-
value: this.saveSelectTriggerRef,
1675-
},
1676-
],
1677-
}}
1671+
ref={this.saveSelectTriggerRef}
16781672
dropdownRender={props.dropdownRender}
16791673
ariaId={this.$data._ariaId}
16801674
>

0 commit comments

Comments
 (0)