Skip to content

Commit f94f50f

Browse files
committed
cr exxx to nxxx
1 parent 4c58c52 commit f94f50f

File tree

22 files changed

+154
-123
lines changed

22 files changed

+154
-123
lines changed

components/empty/__tests__/__snapshots__/demo.test.js.snap

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -92,12 +92,7 @@ exports[`renders ./components/empty/demo/config-provider.md correctly 1`] = `
9292
<div class="ant-list ant-list-split">
9393
<div class="ant-spin-nested-loading">
9494
<div class="ant-spin-container">
95-
<div class="ant-list-empty-text">
96-
<div class="ant-empty ant-empty-normal">
97-
<div class="ant-empty-image"><img alt="No Data" src=""></div>
98-
<p class="ant-empty-description">No Data</p>
99-
</div>
100-
</div>
95+
<div class="ant-list-empty-text"></div>
10196
</div>
10297
</div>
10398
</div>

components/form/FormItem.jsx

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import intersperse from 'intersperse';
21
import PropTypes from '../_util/vue-types';
32
import classNames from 'classnames';
43
import find from 'lodash/find';
@@ -21,6 +20,10 @@ import Icon from '../icon';
2120
import { ConfigConsumerProps } from '../config-provider';
2221

2322
function noop() {}
23+
24+
function intersperseSpace(list) {
25+
return list.reduce((current, item) => [...current, ' ', item], []).slice(1);
26+
}
2427
export const FormItemProps = {
2528
id: PropTypes.string,
2629
prefixCls: PropTypes.string,
@@ -59,7 +62,6 @@ export default {
5962
mixins: [BaseMixin],
6063
props: initDefaultProps(FormItemProps, {
6164
hasFeedback: false,
62-
prefixCls: 'ant-form',
6365
colon: true,
6466
}),
6567
inject: {
@@ -83,8 +85,10 @@ export default {
8385
this.collectFormItemContext(this.$vnode.context, 'delete');
8486
},
8587
mounted() {
88+
const { help, validateStatus } = this.$props;
8689
warning(
87-
this.getControls(this.slotDefault, true).length <= 1,
90+
this.getControls(this.slotDefault, true).length <= 1 ||
91+
(help !== undefined || validateStatus !== undefined),
8892
'`Form.Item` cannot generate `validateStatus` and `help` automatically, ' +
8993
'while there are more than one `getFieldDecorator` in it.',
9094
);
@@ -118,13 +122,16 @@ export default {
118122
if (help === undefined && onlyControl) {
119123
const errors = this.getField().errors;
120124
if (errors) {
121-
return intersperse(
125+
return intersperseSpace(
122126
errors.map((e, index) => {
123-
return isValidElement(e.message)
124-
? cloneElement(e.message, { key: index })
125-
: e.message;
127+
let node = null;
128+
if (isValidElement(e)) {
129+
node = e;
130+
} else if (isValidElement(e.message)) {
131+
node = e.message;
132+
}
133+
return node ? cloneElement(node, { key: index }) : e.message;
126134
}),
127-
' ',
128135
);
129136
} else {
130137
return '';
@@ -339,15 +346,15 @@ export default {
339346
if (!id) {
340347
return;
341348
}
342-
const controls = document.querySelectorAll(`[id="${id}"]`);
343-
if (controls.length !== 1) {
349+
const formItemNode = this.$el;
350+
const control = formItemNode.querySelector(`[id="${id}"]`);
351+
if (control) {
344352
// Only prevent in default situation
345353
// Avoid preventing event in `label={<a href="xx">link</a>}``
346354
if (typeof label === 'string') {
347355
e.preventDefault();
348356
}
349-
const control = this.$el.querySelector(`[id="${id}"]`);
350-
if (control && control.focus) {
357+
if (control.focus) {
351358
control.focus();
352359
}
353360
}

components/form/__tests__/label.test.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,26 @@ import Form from '..';
33
import { asyncExpect } from '@/tests/utils';
44

55
describe('Form', () => {
6+
// Mock of `querySelector`
7+
const originQuerySelector = HTMLElement.prototype.querySelector;
8+
HTMLElement.prototype.querySelector = function querySelector(str) {
9+
const match = str.match(/^\[id=('|")(.*)('|")]$/);
10+
const id = match && match[2];
11+
12+
// Use origin logic
13+
if (id) {
14+
const [input] = this.getElementsByTagName('input');
15+
if (input && input.id === id) {
16+
return input;
17+
}
18+
}
19+
20+
return originQuerySelector.call(this, str);
21+
};
22+
23+
afterAll(() => {
24+
HTMLElement.prototype.querySelector = originQuerySelector;
25+
});
626
it('should remove duplicated user input colon', () => {
727
const wrapper = mount({
828
render() {

components/input/Group.jsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
1+
import PropTypes from '../_util/vue-types';
12
import { filterEmpty } from '../_util/props-util';
23
import { ConfigConsumerProps } from '../config-provider';
34

45
export default {
56
name: 'AInputGroup',
67
props: {
7-
prefixCls: {
8-
type: String,
9-
},
8+
prefixCls: PropTypes.string,
109
size: {
1110
validator(value) {
1211
return ['small', 'large', 'default'].includes(value);

components/input/Input.jsx

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,12 @@ export default {
3838
data() {
3939
const { value, defaultValue } = this.$props;
4040
return {
41-
stateValue: fixControlledValue(!hasProp(this, 'value') ? defaultValue : value),
41+
stateValue: !hasProp(this, 'value') ? defaultValue : value,
4242
};
4343
},
4444
watch: {
4545
value(val) {
46-
this.stateValue = fixControlledValue(val);
46+
this.stateValue = val;
4747
},
4848
},
4949
mounted() {
@@ -95,6 +95,21 @@ export default {
9595
if (!e.target.composing) {
9696
this.$emit('change.value', value);
9797
}
98+
let event = e;
99+
if (e.type === 'click' && this.$refs.input) {
100+
// click clear icon
101+
event = { ...e };
102+
event.target = this.$refs.input;
103+
event.currentTarget = this.$refs.input;
104+
const originalInputValue = this.$refs.input.value;
105+
// change input value cause e.target.value should be '' when clear input
106+
this.$refs.input.value = '';
107+
this.$emit('change', event);
108+
this.$emit('input', event);
109+
// reset input value
110+
this.$refs.input.value = originalInputValue;
111+
return;
112+
}
98113
this.$emit('change', e);
99114
this.$emit('input', e);
100115
},
@@ -129,7 +144,7 @@ export default {
129144
let suffix = getComponentFromProp(this, 'suffix');
130145
if (suffix || allowClear) {
131146
return (
132-
<span class={`${prefixCls}-suffix`}>
147+
<span class={`${prefixCls}-suffix`} key="suffix">
133148
{this.renderClearIcon(prefixCls)}
134149
{suffix}
135150
</span>
@@ -179,14 +194,18 @@ export default {
179194
return children;
180195
}
181196
let prefix = getComponentFromProp(this, 'prefix');
182-
prefix = prefix ? <span class={`${prefixCls}-prefix`}>{prefix}</span> : null;
197+
prefix = prefix ? (
198+
<span class={`${prefixCls}-prefix`} key="prefix">
199+
{prefix}
200+
</span>
201+
) : null;
183202

184203
const affixWrapperCls = classNames(`${prefixCls}-affix-wrapper`, {
185204
[`${prefixCls}-affix-wrapper-sm`]: size === 'small',
186205
[`${prefixCls}-affix-wrapper-lg`]: size === 'large',
187206
});
188207
return (
189-
<span class={affixWrapperCls}>
208+
<span class={affixWrapperCls} key="affix">
190209
{prefix}
191210
{children}
192211
{suffix}
@@ -201,13 +220,14 @@ export default {
201220
'addonAfter',
202221
'prefix',
203222
'suffix',
223+
'allowClear',
204224
'value',
205225
'defaultValue',
206226
]);
207227
const { stateValue, getInputClassName, handleKeyDown, handleChange, $listeners } = this;
208228
const inputProps = {
209229
domProps: {
210-
value: stateValue,
230+
value: fixControlledValue(stateValue),
211231
},
212232
attrs: { ...otherProps, ...this.$attrs },
213233
on: {
@@ -218,6 +238,7 @@ export default {
218238
},
219239
class: getInputClassName(prefixCls),
220240
ref: 'input',
241+
key: 'ant-input',
221242
};
222243
if ($listeners['change.value']) {
223244
inputProps.directives = [{ name: 'ant-input' }];

components/input/Password.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,6 @@ import classNames from 'classnames';
22
import Input from './Input';
33
import Icon from '../icon';
44
import inputProps from './inputProps';
5-
import Button from '../button';
6-
import { cloneElement } from '../_util/vnode';
7-
import { getOptionProps, getComponentFromProp, isValidElement } from '../_util/props-util';
85
import PropTypes from '../_util/vue-types';
96
import BaseMixin from '../_util/BaseMixin';
107

@@ -47,7 +44,7 @@ export default {
4744
},
4845
on: {
4946
[iconTrigger]: this.onChange,
50-
onMouseDown: e => {
47+
mousedown: e => {
5148
// Prevent focused state lost
5249
// https://github.com/ant-design/ant-design/issues/15173
5350
e.preventDefault();

components/input/Search.jsx

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,6 @@ export default {
1717
},
1818
props: {
1919
...inputProps,
20-
prefixCls: {
21-
default: 'ant-input-search',
22-
type: String,
23-
},
24-
inputPrefixCls: {
25-
default: 'ant-input',
26-
type: String,
27-
},
2820
enterButton: PropTypes.oneOfType([PropTypes.bool, PropTypes.string, PropTypes.object]),
2921
},
3022
inject: {
@@ -52,13 +44,13 @@ export default {
5244
);
5345

5446
if (suffix) {
55-
let cloneSuffix = suffix;
56-
if (isValidElement(cloneSuffix) && !cloneSuffix.key) {
57-
cloneSuffix = cloneElement(cloneSuffix, {
58-
key: 'originSuffix',
59-
});
60-
}
61-
return [cloneSuffix, node];
47+
// let cloneSuffix = suffix;
48+
// if (isValidElement(cloneSuffix) && !cloneSuffix.key) {
49+
// cloneSuffix = cloneElement(cloneSuffix, {
50+
// key: 'originSuffix',
51+
// });
52+
// }
53+
return [suffix, node];
6254
}
6355

6456
return node;

components/input/__tests__/__snapshots__/demo.test.js.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ exports[`renders ./components/input/demo/addon.md correctly 1`] = `
1010
</div>
1111
`;
1212

13-
exports[`renders ./components/input/demo/allowClear.md correctly 1`] = `<span class="ant-input-affix-wrapper"><input placeholder="input with clear icon" type="text" allowclear="true" class="ant-input"><span class="ant-input-suffix"></span></span>`;
13+
exports[`renders ./components/input/demo/allowClear.md correctly 1`] = `<span class="ant-input-affix-wrapper"><input placeholder="input with clear icon" type="text" class="ant-input"><span class="ant-input-suffix"></span></span>`;
1414
1515
exports[`renders ./components/input/demo/autosize-textarea.md correctly 1`] = `
1616
<div><textarea placeholder="Autosize height based on content lines" class="ant-input"></textarea>

components/input/demo/tooltip.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ You can use the Input in conjunction with [Tooltip](/components/tooltip/) compon
2727
@change="onChange"
2828
@blur="onBlur"
2929
placeholder="Input a number"
30-
maxLength="25"
30+
:maxLength="25"
3131
style="width: 120px"
3232
/>
3333
</a-tooltip>

components/input/index.en-US.md

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -68,21 +68,8 @@ Supports all props of `Input`.
6868
<a-input />
6969
</a-input-group>
7070
````
71-
#### Input.Password
71+
#### Input.Password (Added in 1.14.0)
7272

7373
| Property | Description | Type | Default |
7474
| --- | --- | --- | --- |
7575
| visibilityToggle | Whether show toggle button | boolean | true |
76-
77-
## FAQ
78-
79-
### Why Input lose focus when change `prefix/suffix`
80-
81-
When Input dynamic add or remove `prefix/suffix` will make Vue recreate the dom structure and new input will be not focused.
82-
You can set an empty `<span />` element to keep the dom structure:
83-
84-
```jsx
85-
const suffix = condition ? <Icon type="smile" /> : <span />;
86-
87-
<Input suffix={suffix} />
88-
```

0 commit comments

Comments
 (0)