Skip to content

Commit 0178c35

Browse files
committed
perf: input icon grid
1 parent 4d6627d commit 0178c35

File tree

9 files changed

+112
-49
lines changed

9 files changed

+112
-49
lines changed

components/grid/Row.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ export default {
105105
getGutter () {
106106
const { gutter } = this
107107
if (typeof gutter === 'object') {
108-
for (let i = 0; i <= responsiveArray.length; i++) {
108+
for (let i = 0; i < responsiveArray.length; i++) {
109109
const breakpoint = responsiveArray[i]
110110
if (this.screens[breakpoint] && gutter[breakpoint] !== undefined) {
111111
return gutter[breakpoint]

components/icon/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ const Icon = {
112112
` the 'theme' prop '${theme}' will be ignored.`)
113113
}
114114
computedType = withThemeSuffix(
115-
removeTypeTheme(alias(type)),
115+
removeTypeTheme(alias(computedType)),
116116
dangerousTheme || theme || defaultTheme,
117117
)
118118
innerNode = (

components/input/Input.jsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,8 @@ export default {
171171
'addonAfter',
172172
'prefix',
173173
'suffix',
174+
'value',
175+
'defaultValue',
174176
])
175177
const { stateValue, getInputClassName, handleKeyDown, handleChange, $listeners } = this
176178
const inputProps = {

components/input/TextArea.jsx

Lines changed: 38 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11

22
import omit from 'omit.js'
3+
import ResizeObserver from 'resize-observer-polyfill'
34
import inputProps from './inputProps'
45
import calculateNodeHeight from './calculateNodeHeight'
56
import hasProp from '../_util/props-util'
@@ -47,22 +48,53 @@ export default {
4748
},
4849
watch: {
4950
value (val) {
51+
this.$nextTick(() => {
52+
this.resizeOnNextFrame()
53+
})
5054
this.stateValue = fixControlledValue(val)
51-
if (this.nextFrameActionId) {
52-
clearNextFrameAction(this.nextFrameActionId)
55+
},
56+
autosize (val) {
57+
if (!val && this.$refs.textArea) {
58+
this.textareaStyles = omit(this.textareaStyles, ['overflowY'])
5359
}
54-
this.nextFrameActionId = onNextFrame(this.resizeTextarea)
5560
},
5661
},
5762
mounted () {
5863
this.$nextTick(() => {
5964
this.resizeTextarea()
65+
this.updateResizeObserverHook()
6066
if (this.autoFocus) {
6167
this.focus()
6268
}
6369
})
6470
},
71+
updated () {
72+
this.updateResizeObserverHook()
73+
},
74+
beforeDestroy () {
75+
if (this.resizeObserver) {
76+
this.resizeObserver.disconnect()
77+
}
78+
},
6579
methods: {
80+
resizeOnNextFrame () {
81+
if (this.nextFrameActionId) {
82+
clearNextFrameAction(this.nextFrameActionId)
83+
}
84+
this.nextFrameActionId = onNextFrame(this.resizeTextarea)
85+
},
86+
// We will update hooks if `autosize` prop change
87+
updateResizeObserverHook () {
88+
if (!this.resizeObserver && this.$props.autosize) {
89+
// Add resize observer
90+
this.resizeObserver = new ResizeObserver(this.resizeOnNextFrame)
91+
this.resizeObserver.observe(this.$refs.textArea)
92+
} else if (this.resizeObserver && !this.$props.autosize) {
93+
// Remove resize observer
94+
this.resizeObserver.disconnect()
95+
this.resizeObserver = null
96+
}
97+
},
6698
handleKeyDown (e) {
6799
if (e.keyCode === 13) {
68100
this.$emit('pressEnter', e)
@@ -91,9 +123,7 @@ export default {
91123
handleTextareaChange (e) {
92124
if (!hasProp(this, 'value')) {
93125
this.stateValue = e.target.value
94-
this.$nextTick(() => {
95-
this.resizeTextarea()
96-
})
126+
this.resizeTextarea()
97127
} else {
98128
this.$forceUpdate()
99129
}
@@ -126,6 +156,8 @@ export default {
126156
'prefixCls',
127157
'autosize',
128158
'type',
159+
'value',
160+
'defaultValue',
129161
])
130162
const textareaProps = {
131163
attrs: { ...otherProps, ...$attrs },

components/input/calculateNodeHeight.js

Lines changed: 31 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,15 @@
55
*/
66

77
const HIDDEN_TEXTAREA_STYLE = `
8-
min-height:0 !important;
9-
max-height:none !important;
10-
height:0 !important;
11-
visibility:hidden !important;
12-
overflow:hidden !important;
13-
position:absolute !important;
14-
z-index:-1000 !important;
15-
top:0 !important;
16-
right:0 !important
8+
min-height:0 !important;
9+
max-height:none !important;
10+
height:0 !important;
11+
visibility:hidden !important;
12+
overflow:hidden !important;
13+
position:absolute !important;
14+
z-index:-1000 !important;
15+
top:0 !important;
16+
right:0 !important
1717
`
1818

1919
const SIZING_STYLE = [
@@ -38,37 +38,30 @@ const computedStyleCache = {}
3838
let hiddenTextarea
3939

4040
function calculateNodeStyling (node, useCache = false) {
41-
const nodeRef = (
42-
node.getAttribute('id') ||
43-
node.getAttribute('data-reactid') ||
44-
node.getAttribute('name')
45-
)
41+
const nodeRef = (node.getAttribute('id') ||
42+
node.getAttribute('data-reactid') ||
43+
node.getAttribute('name'))
4644

4745
if (useCache && computedStyleCache[nodeRef]) {
4846
return computedStyleCache[nodeRef]
4947
}
5048

5149
const style = window.getComputedStyle(node)
5250

53-
const boxSizing = (
51+
const boxSizing =
5452
style.getPropertyValue('box-sizing') ||
55-
style.getPropertyValue('-moz-box-sizing') ||
56-
style.getPropertyValue('-webkit-box-sizing')
57-
)
53+
style.getPropertyValue('-moz-box-sizing') ||
54+
style.getPropertyValue('-webkit-box-sizing')
5855

59-
const paddingSize = (
56+
const paddingSize =
6057
parseFloat(style.getPropertyValue('padding-bottom')) +
61-
parseFloat(style.getPropertyValue('padding-top'))
62-
)
58+
parseFloat(style.getPropertyValue('padding-top'))
6359

64-
const borderSize = (
60+
const borderSize =
6561
parseFloat(style.getPropertyValue('border-bottom-width')) +
66-
parseFloat(style.getPropertyValue('border-top-width'))
67-
)
62+
parseFloat(style.getPropertyValue('border-top-width'))
6863

69-
const sizingStyle = SIZING_STYLE
70-
.map(name => `${name}:${style.getPropertyValue(name)}`)
71-
.join(';')
64+
const sizingStyle = SIZING_STYLE.map(name => `${name}:${style.getPropertyValue(name)}`).join(';')
7265

7366
const nodeInfo = {
7467
sizingStyle,
@@ -105,33 +98,33 @@ export default function calculateNodeHeight (
10598

10699
// Copy all CSS properties that have an impact on the height of the content in
107100
// the textbox
108-
const {
109-
paddingSize, borderSize,
110-
boxSizing, sizingStyle,
111-
} = calculateNodeStyling(uiTextNode, useCache)
101+
const { paddingSize, borderSize, boxSizing, sizingStyle } = calculateNodeStyling(
102+
uiTextNode,
103+
useCache,
104+
)
112105

113106
// Need to have the overflow attribute to hide the scrollbar otherwise
114107
// text-lines will not calculated properly as the shadow will technically be
115108
// narrower for content
116109
hiddenTextarea.setAttribute('style', `${sizingStyle};${HIDDEN_TEXTAREA_STYLE}`)
117110
hiddenTextarea.value = uiTextNode.value || uiTextNode.placeholder || ''
118111

119-
let minHeight = -Infinity
120-
let maxHeight = Infinity
112+
let minHeight = Number.MIN_SAFE_INTEGER
113+
let maxHeight = Number.MAX_SAFE_INTEGER
121114
let height = hiddenTextarea.scrollHeight
122115
let overflowY
123116

124117
if (boxSizing === 'border-box') {
125-
// border-box: add border, since height = content + padding + border
118+
// border-box: add border, since height = content + padding + border
126119
height = height + borderSize
127120
} else if (boxSizing === 'content-box') {
128-
// remove padding, since height = content
121+
// remove padding, since height = content
129122
height = height - paddingSize
130123
}
131124

132125
if (minRows !== null || maxRows !== null) {
133-
// measure height of a textarea with a single row
134-
hiddenTextarea.value = ''
126+
// measure height of a textarea with a single row
127+
hiddenTextarea.value = ' '
135128
const singleRowHeight = hiddenTextarea.scrollHeight - paddingSize
136129
if (minRows !== null) {
137130
minHeight = singleRowHeight * minRows
@@ -150,6 +143,7 @@ export default function calculateNodeHeight (
150143
}
151144
}
152145
// Remove scroll bar flash when autosize without maxRows
146+
// donot remove in vue
153147
if (!maxRows) {
154148
overflowY = 'hidden'
155149
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<cn>
2+
#### 文本域
3+
用于多行输入。
4+
</cn>
5+
6+
<us>
7+
#### TextArea
8+
For multi-line input.
9+
</us>
10+
11+
```html
12+
<template>
13+
<div>
14+
<a-button @click="() => this.autoResize = !autoResize">
15+
Auto Resize: {String(autoResize)}
16+
</a-button>
17+
<a-textarea :rows="4" :autosize="autoResize" :defaultValue="defaultValue" />
18+
</div>
19+
</template>
20+
<script>
21+
export default {
22+
data:()=>({
23+
autoResize: false,
24+
defaultValue: 'autosize 属性适用于 textarea 节点,并且只有高度会自动变化。另外 autosize 可以设定为一个对象,指定最小行数和最大行数。autosize 属性适用于 textarea 节点,并且只有高度会自动变化。另外 autosize 可以设定为一个对象,指定最小行数和最大行数。autosize 属性适用于 textarea 节点,并且只有高度会自动变化。另外 autosize 可以设定为一个对象,指定最小行数和最大行数。autosize 属性适用于 textarea 节点,并且只有高度会自动变化。另外 autosize 可以设定为一个对象,指定最小行数和最大行数。autosize 属性适用于 textarea 节点,并且只有高度会自动变化。另外 autosize 可以设定为一个对象,指定最小行数和最大行数。autosize 属性适用于 textarea 节点,并且只有高度会自动变化。另外 autosize 可以设定为一个对象,指定最小行数和最大行数。autosize 属性适用于 textarea 节点,并且只有高度会自动变化。另外 autosize 可以设定为一个对象,指定最小行数和最大行数。ending',
25+
})
26+
}
27+
</script>
28+
```

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@
178178
"mutationobserver-shim": "^0.3.2",
179179
"omit.js": "^1.0.0",
180180
"raf": "^3.4.0",
181-
"resize-observer-polyfill": "^1.5.0",
181+
"resize-observer-polyfill": "^1.5.1",
182182
"shallow-equal": "^1.0.0",
183183
"shallowequal": "^1.0.2",
184184
"vue-ref": "^1.0.3",

types/badge.d.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,14 @@
33
// Definitions: https://github.com/vueComponent/ant-design-vue/types
44

55
import { AntdComponent } from './component';
6+
import { VNode } from 'vue';
67

78
export declare class Badge extends AntdComponent {
89
/**
9-
* Number to show in badge
10-
* @type number | string
10+
* Number to show in badge, support slot
11+
* @type number | string | VNode
1112
*/
12-
count: number | string;
13+
count: number | string | VNode;
1314

1415
/**
1516
* to display a red dot instead of count

types/cascader.d.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,12 @@ export interface ShowSearchType {
3838
* @type boolean
3939
*/
4040
matchInputWidth?: boolean;
41+
42+
/**
43+
* Set the count of filtered items
44+
* @type number | false
45+
*/
46+
limit?: number | false;
4147
}
4248

4349
export declare class Cascader extends AntdComponent {

0 commit comments

Comments
 (0)