Skip to content

Commit 89c9e81

Browse files
committed
fix: select input width
1 parent ad6f343 commit 89c9e81

File tree

8 files changed

+55
-64
lines changed

8 files changed

+55
-64
lines changed

antdv-demo

components/_util/antDirective.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
import ref from 'vue-ref';
2-
import { antInput } from './antInputDirective';
2+
// import { antInput } from './antInputDirective';
33
import { antDecorator } from './FormDecoratorDirective';
44
import { antPortal } from './portalDirective';
55

66
export default {
77
install: Vue => {
88
Vue.use(ref, { name: 'ant-ref' });
9-
antInput(Vue);
109
antDecorator(Vue);
1110
antPortal(Vue);
1211
},

components/_util/antInputDirective.js

+20-21
Original file line numberDiff line numberDiff line change
@@ -44,30 +44,29 @@ if (isIE9) {
4444
});
4545
}
4646

47-
export function antInput(Vue) {
48-
return Vue.directive('ant-input', {
49-
inserted(el, binding, vnode) {
50-
if (vnode.tag === 'textarea' || isTextInputType(el.type)) {
51-
if (!binding.modifiers || !binding.modifiers.lazy) {
52-
el.addEventListener('compositionstart', onCompositionStart);
53-
el.addEventListener('compositionend', onCompositionEnd);
54-
// Safari < 10.2 & UIWebView doesn't fire compositionend when
55-
// switching focus before confirming composition choice
56-
// this also fixes the issue where some browsers e.g. iOS Chrome
57-
// fires "change" instead of "input" on autocomplete.
58-
el.addEventListener('change', onCompositionEnd);
59-
/* istanbul ignore if */
60-
if (isIE9) {
61-
el.vmodel = true;
62-
}
47+
export const antInput = {
48+
mounted(el, binding, vnode) {
49+
if (vnode.type === 'textarea' || isTextInputType(el.type)) {
50+
if (!binding.modifiers || !binding.modifiers.lazy) {
51+
el.addEventListener('compositionstart', onCompositionStart);
52+
el.addEventListener('compositionend', onCompositionEnd);
53+
// Safari < 10.2 & UIWebView doesn't fire compositionend when
54+
// switching focus before confirming composition choice
55+
// this also fixes the issue where some browsers e.g. iOS Chrome
56+
// fires "change" instead of "input" on autocomplete.
57+
el.addEventListener('change', onCompositionEnd);
58+
/* istanbul ignore if */
59+
if (isIE9) {
60+
el.vmodel = true;
6361
}
6462
}
65-
},
66-
});
67-
}
63+
}
64+
},
65+
};
6866

6967
export default {
70-
install: Vue => {
71-
antInput(Vue);
68+
install: app => {
69+
antInput(app);
70+
app.directive('ant-input', antInput);
7271
},
7372
};

components/vc-select/OptGroup.jsx

+3
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,7 @@ export default {
55
label: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
66
},
77
isSelectOptGroup: true,
8+
render() {
9+
return null;
10+
},
811
};

components/vc-select/Option.jsx

+3
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,7 @@ export default {
88
title: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
99
},
1010
isSelectOption: true,
11+
render() {
12+
return null;
13+
},
1114
};

components/vc-select/Select.jsx

+25-38
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {TransitionGroup} from 'vue';
1+
import { TransitionGroup } from 'vue';
22
import KeyCode from '../_util/KeyCode';
33
import PropTypes from '../_util/vue-types';
44
import classnames from 'classnames';
@@ -149,7 +149,7 @@ const Select = {
149149
};
150150
return {
151151
...state,
152-
_mirrorInputValue: state._inputValue, // https://github.com/vueComponent/ant-design-vue/issues/1458
152+
// _mirrorInputValue: state._inputValue, // https://github.com/vueComponent/ant-design-vue/issues/1458
153153
...this.getDerivedState(props, state),
154154
};
155155
},
@@ -170,22 +170,10 @@ const Select = {
170170
__propsSymbol__() {
171171
Object.assign(this.$data, this.getDerivedState(getOptionProps(this), this.$data));
172172
},
173-
_inputValue(val) {
174-
this.$data._mirrorInputValue = val;
175-
},
176173
},
177174
updated() {
178175
this.$nextTick(() => {
179-
if (isMultipleOrTags(this.$props)) {
180-
const inputNode = this.getInputDOMNode();
181-
const mirrorNode = this.getInputMirrorDOMNode();
182-
if (inputNode && inputNode.value && mirrorNode) {
183-
inputNode.style.width = '';
184-
inputNode.style.width = `${mirrorNode.clientWidth + 10}px`;
185-
} else if (inputNode) {
186-
inputNode.style.width = '';
187-
}
188-
}
176+
this.updateInputWidth();
189177
this.forcePopupAlign();
190178
});
191179
},
@@ -199,6 +187,18 @@ const Select = {
199187
}
200188
},
201189
methods: {
190+
updateInputWidth() {
191+
if (isMultipleOrTags(this.$props)) {
192+
const inputNode = this.getInputDOMNode();
193+
const mirrorNode = this.getInputMirrorDOMNode();
194+
if (inputNode && inputNode.value && mirrorNode) {
195+
inputNode.style.width = '';
196+
inputNode.style.width = `${mirrorNode.clientWidth + 10}px`;
197+
} else if (inputNode) {
198+
inputNode.style.width = '';
199+
}
200+
}
201+
},
202202
getDerivedState(nextProps, prevState) {
203203
const optionsInfo = prevState._skipBuildOptionsInfo
204204
? prevState._optionsInfo
@@ -310,14 +310,7 @@ const Select = {
310310
},
311311

312312
onInputChange(e) {
313-
const { value: val, composing } = e.target;
314-
const { _inputValue = '' } = this.$data;
315-
if (e.isComposing || composing || _inputValue === val) {
316-
this.setState({
317-
_mirrorInputValue: val,
318-
});
319-
return;
320-
}
313+
const { value: val } = e.target;
321314
const { tokenSeparators } = this.$props;
322315
if (
323316
isMultipleOrTags(this.$props) &&
@@ -639,20 +632,14 @@ const Select = {
639632
getPlaceholderElement() {
640633
const { $props: props, $data: state } = this;
641634
let hidden = false;
642-
if (state._mirrorInputValue) {
635+
if (state._inputValue) {
643636
hidden = true;
644637
}
645638
const value = state._value;
646639
if (value.length) {
647640
hidden = true;
648641
}
649-
if (
650-
!state._mirrorInputValue &&
651-
isCombobox(props) &&
652-
value.length === 1 &&
653-
state._value &&
654-
!state._value[0]
655-
) {
642+
if (isCombobox(props) && value.length === 1 && state._value && !state._value[0]) {
656643
hidden = false;
657644
}
658645
const placeholder = props.placeholder;
@@ -781,9 +768,11 @@ const Select = {
781768
},
782769
_getInputElement() {
783770
const props = this.$props;
784-
const { _inputValue: inputValue, _mirrorInputValue } = this.$data;
771+
const { _inputValue: inputValue } = this.$data;
785772
const attrs = this.$attrs;
786-
const defaultInput = <input {...(attrs.id !== undefined ? {id: attrs.id}: {})} autoComplete="off"/>;
773+
const defaultInput = (
774+
<input {...(attrs.id !== undefined ? { id: attrs.id } : {})} autoComplete="off" />
775+
);
787776

788777
const inputElement = props.getInputElement ? props.getInputElement() : defaultInput;
789778
const inputCls = classnames(inputElement.class, {
@@ -816,7 +805,7 @@ const Select = {
816805
onBlur: chaining(this.inputBlur, inputEvents.onBlur),
817806
})}
818807
<span ref={this.saveInputMirrorRef} class={`${props.prefixCls}-search__field__mirror`}>
819-
{_mirrorInputValue}&nbsp;
808+
{inputValue}&nbsp;
820809
</span>
821810
</div>
822811
);
@@ -1206,7 +1195,7 @@ const Select = {
12061195
});
12071196

12081197
sel.push(
1209-
<MenuItemGroup key={key} title={label} class={child.props?.class}>
1198+
<MenuItemGroup key={key} title={label} class={child.props && child.props.class}>
12101199
{...innerItems}
12111200
</MenuItemGroup>,
12121201
);
@@ -1411,9 +1400,7 @@ const Select = {
14111400
tag: 'ul',
14121401
onAfterLeave: this.onChoiceAnimationLeave,
14131402
});
1414-
innerNode = (
1415-
<TransitionGroup {...transitionProps}>{selectedValueNodes}</TransitionGroup>
1416-
);
1403+
innerNode = <TransitionGroup {...transitionProps}>{selectedValueNodes}</TransitionGroup>;
14171404
} else {
14181405
innerNode = <ul>{selectedValueNodes}</ul>;
14191406
}

examples/App.vue

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
</div>
55
</template>
66
<script>
7-
import demo from '../antdv-demo/docs/select/demo/tags';
7+
import demo from '../antdv-demo/docs/auto-complete/demo/index';
88
99
export default {
1010
components: {

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@
152152
"terser-webpack-plugin": "^3.0.3",
153153
"through2": "^3.0.0",
154154
"url-loader": "^3.0.0",
155-
"vue": "^3.0.0-beta.17",
155+
"vue": "^3.0.0-beta.18",
156156
"vue-antd-md-loader": "^1.1.0",
157157
"vue-clipboard2": "0.3.1",
158158
"vue-draggable-resizable": "^2.1.0",

0 commit comments

Comments
 (0)