Skip to content

Commit b0990b7

Browse files
committed
Merge remote-tracking branch 'origin/main' into feat-v4
2 parents 5376014 + c36b69d commit b0990b7

File tree

22 files changed

+128
-63
lines changed

22 files changed

+128
-63
lines changed

components/button/__tests__/index.test.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,12 @@ import { nextTick } from 'vue';
55
import { asyncExpect, sleep } from '../../../tests/utils';
66
import mountTest from '../../../tests/shared/mountTest';
77
import { resetWarned } from '../../_util/warning';
8+
import focusTest from '../../../tests/shared/focusTest';
89

910
describe('Button', () => {
1011
mountTest(Button);
1112
mountTest(Button.Group);
13+
focusTest(Button);
1214
it('renders correctly', () => {
1315
const wrapper = mount({
1416
render() {

components/button/button.tsx

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ export default defineComponent({
3838
props: initDefaultProps(buttonProps(), { type: 'default' }),
3939
slots: ['icon'],
4040
// emits: ['click', 'mousedown'],
41-
setup(props, { slots, attrs, emit }) {
41+
setup(props, { slots, attrs, emit, expose }) {
4242
const { prefixCls, autoInsertSpaceInButton, direction, size } = useConfigInject('btn', props);
4343
const [wrapSSR, hashId] = useStyle(prefixCls);
4444
const groupSizeContext = GroupSizeContext.useInject();
@@ -157,6 +157,17 @@ export default defineComponent({
157157
delayTimeoutRef.value && clearTimeout(delayTimeoutRef.value);
158158
});
159159

160+
const focus = () => {
161+
buttonNodeRef.value?.focus();
162+
};
163+
const blur = () => {
164+
buttonNodeRef.value?.blur();
165+
};
166+
expose({
167+
focus,
168+
blur,
169+
});
170+
160171
return () => {
161172
const { icon = slots.icon?.() } = props;
162173
const children = flattenChildren(slots.default?.());

components/button/index.en-US.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,15 @@ It accepts all props which native buttons support.
5656

5757
## FAQ
5858

59+
### Methods
60+
61+
#### Checkbox
62+
63+
| Name | Description | Version |
64+
| ------- | ------------ | ------- |
65+
| blur() | remove focus | |
66+
| focus() | get focus | |
67+
5968
### How to remove space between 2 chinese characters
6069

6170
Following the Ant Design specification, we will add one space between if Button (exclude Text button and Link button) contains two Chinese characters only. If you don't need that, you can use [ConfigProvider](/components/config-provider/#api) to set `autoInsertSpaceInButton` as `false`.

components/button/index.zh-CN.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,15 @@ coverDark: https://mdn.alipayobjects.com/huamei_7uahnr/afts/img/A*Lp1kTYmSsgoAAA
5757

5858
支持原生 button 的其他所有属性。
5959

60+
### 方法
61+
62+
#### Button
63+
64+
| 名称 | 描述 | 版本 |
65+
| ------- | -------- | ---- |
66+
| blur() | 移除焦点 | |
67+
| focus() | 获取焦点 | |
68+
6069
## FAQ
6170

6271
### 如何移除 2 个汉字之间的空格

components/date-picker/index.en-US.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,3 +211,20 @@ Please refer [replace date](/docs/vue/replace-date)
211211
### Why config dayjs.locale globally not work?
212212

213213
DatePicker default set `locale` as `en` in v4. You can config DatePicker `locale` prop or [ConfigProvider `locale`](/components/config-provider) prop instead.
214+
215+
### How to modify start day of week?
216+
217+
Please use correct [language](/docs/vue/i18n) ([#5605](https://github.com/ant-design/ant-design/issues/5605)), or update dayjs `locale` config:
218+
219+
- Example: <https://codesandbox.io/s/dayjs-day-of-week-x9tuj2?file=/demo.tsx>
220+
221+
```js
222+
import dayjs from 'dayjs';
223+
import updateLocale from 'dayjs/plugin/updateLocale';
224+
import 'dayjs/locale/zh-cn';
225+
226+
dayjs.extend(updateLocale);
227+
dayjs.updateLocale('zh-cn', {
228+
weekStart: 0,
229+
});
230+
```

components/date-picker/index.zh-CN.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,3 +212,18 @@ export type FormatType = Generic | GenericFn | Array<Generic | GenericFn>;
212212
### 为何全局修改 dayjs.locale 不生效?
213213

214214
DatePicker 默认 `locale``en`。你可以通过 DatePicker 的 `locale` 属性来单独设置,也可以通过 [ConfigProvider `locale`](/components/config-provider-cn) 属性来配置。
215+
216+
### 如何修改周的起始日?
217+
218+
请使用正确的[语言包](/docs/vue/i18n-cn)[#5605](https://github.com/ant-design/ant-design/issues/5605)),或者修改 dayjs 的 `locale` 配置:<https://codesandbox.io/s/dayjs-day-of-week-x9tuj2?file=/demo.tsx>
219+
220+
```js
221+
import dayjs from 'dayjs';
222+
import updateLocale from 'dayjs/plugin/updateLocale';
223+
import 'dayjs/locale/zh-cn';
224+
225+
dayjs.extend(updateLocale);
226+
dayjs.updateLocale('zh-cn', {
227+
weekStart: 0,
228+
});
229+
```

components/form/FormItem.tsx

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,12 @@ import { warning } from '../vc-util/warning';
3434
import find from 'lodash-es/find';
3535
import { tuple } from '../_util/type';
3636
import type {
37+
FormLabelAlign,
3738
InternalNamePath,
3839
Rule,
3940
RuleError,
4041
RuleObject,
4142
ValidateOptions,
42-
FormLabelAlign,
4343
} from './interface';
4444
import useConfigInject from '../config-provider/hooks/useConfigInject';
4545
import { useInjectForm } from './context';
@@ -113,10 +113,7 @@ export const formItemProps = () => ({
113113
wrapperCol: { type: Object as PropType<ColProps & HTMLAttributes> },
114114
hasFeedback: { type: Boolean, default: false },
115115
colon: { type: Boolean, default: undefined },
116-
labelAlign: {
117-
...PropTypes.oneOf(tuple('left', 'right')),
118-
type: String as PropType<FormLabelAlign>,
119-
},
116+
labelAlign: String as PropType<FormLabelAlign>,
120117
prop: { type: [String, Number, Array] as PropType<string | number | Array<string | number>> },
121118
name: { type: [String, Number, Array] as PropType<string | number | Array<string | number>> },
122119
rules: [Array, Object] as PropType<Rule[] | Rule>,
@@ -237,7 +234,7 @@ export default defineComponent({
237234
if (typeof props.label === 'string') {
238235
variables.label = props.label;
239236
} else if (props.name) {
240-
variables.label = String(name);
237+
variables.label = String(props.name);
241238
}
242239
if (props.messageVariables) {
243240
variables = { ...variables, ...props.messageVariables };

components/mentions/index.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@ import type { App, PropType, ExtractPropTypes } from 'vue';
22
import { computed, watch, shallowRef, defineComponent } from 'vue';
33
import classNames from '../_util/classNames';
44
import PropTypes from '../_util/vue-types';
5-
import VcMentions, { Option } from '../vc-mentions';
5+
import VcMentions from '../vc-mentions';
66
import { mentionsProps as baseMentionsProps } from '../vc-mentions/src/mentionsProps';
77
import useConfigInject from '../config-provider/hooks/useConfigInject';
88
import { flattenChildren, getOptionProps } from '../_util/props-util';
99
import { FormItemInputContext, useInjectFormItemContext } from '../form/FormItemContext';
1010
import omit from '../_util/omit';
11-
import { optionProps } from '../vc-mentions/src/Option';
11+
import { optionProps, optionOptions } from '../vc-mentions/src/Option';
1212
import type { KeyboardEventHandler } from '../_util/EventInterface';
1313
import type { InputStatus } from '../_util/statusUtils';
1414
import { getStatusClassNames, getMergedStatus } from '../_util/statusUtils';
@@ -279,7 +279,7 @@ const Mentions = defineComponent({
279279
/* istanbul ignore next */
280280
export const MentionsOption = defineComponent({
281281
compatConfig: { MODE: 3 },
282-
...(Option as any),
282+
...optionOptions,
283283
name: 'AMentionsOption',
284284
props: optionProps,
285285
});

components/table/index.tsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import Table, { tableProps } from './Table';
22
import Column from './Column';
33
import ColumnGroup from './ColumnGroup';
44
import type { TableProps, TablePaginationConfig } from './Table';
5-
import { defineComponent } from 'vue';
65
import type { App } from 'vue';
76
import { EXPAND_COLUMN, Summary, SummaryCell, SummaryRow } from '../vc-table';
87
import {
@@ -16,8 +15,8 @@ export type { ColumnProps } from './Column';
1615
export type { ColumnsType, ColumnType, ColumnGroupType } from './interface';
1716
export type { TableProps, TablePaginationConfig };
1817

19-
const TableSummaryRow = defineComponent({ ...(SummaryRow as any), name: 'ATableSummaryRow' });
20-
const TableSummaryCell = defineComponent({ ...(SummaryCell as any), name: 'ATableSummaryCell' });
18+
const TableSummaryRow = SummaryRow;
19+
const TableSummaryCell = SummaryCell;
2120

2221
const TableSummary = Object.assign(Summary, {
2322
Cell: TableSummaryCell,

components/transfer/demo/tree-transfer.vue

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -78,14 +78,12 @@ function isChecked(selectedKeys: (string | number)[], eventKey: string | number)
7878
return selectedKeys.indexOf(eventKey) !== -1;
7979
}
8080
81-
function handleTreeData(data: TransferProps['dataSource'], targetKeys: string[] = []) {
82-
data.forEach(item => {
83-
item['disabled'] = targetKeys.includes(item.key as any);
84-
if (item.children) {
85-
handleTreeData(item.children, targetKeys);
86-
}
87-
});
88-
return data as TreeProps['treeData'];
81+
function handleTreeData(treeNodes: TransferProps['dataSource'], targetKeys: string[] = []) {
82+
return treeNodes.map(({ children, ...props }) => ({
83+
...props,
84+
disabled: targetKeys.includes(props.key as string),
85+
children: handleTreeData(children ?? [], targetKeys),
86+
}));
8987
}
9088
9189
export default defineComponent({

components/tree/index.tsx

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
import type { App } from 'vue';
2-
import { defineComponent } from 'vue';
32
import Tree from './Tree';
43
import { TreeNode as VcTreeNode } from '../vc-tree';
54
import DirectoryTree from './DirectoryTree';
6-
import { treeNodeProps } from '../vc-tree/props';
75

86
export type { EventDataNode, DataNode } from '../vc-tree/interface';
97

@@ -26,11 +24,7 @@ export type {
2624

2725
/* istanbul ignore next */
2826

29-
const TreeNode = defineComponent({
30-
...(VcTreeNode as any),
31-
name: 'ATreeNode',
32-
props: treeNodeProps,
33-
});
27+
const TreeNode = VcTreeNode;
3428

3529
export { DirectoryTree, TreeNode };
3630

components/vc-mentions/src/Option.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,14 @@ export type BaseOptionsProps = Partial<ExtractPropTypes<typeof baseOptionsProps>
1717

1818
export type OptionProps = Partial<ExtractPropTypes<typeof optionProps>> & Partial<HTMLAttributes>;
1919

20-
export default defineComponent({
21-
compatConfig: { MODE: 3 },
20+
export const optionOptions = {
2221
name: 'Option',
2322
props: optionProps,
2423
render(_props: any, { slots }: any) {
2524
return slots.default?.();
2625
},
26+
};
27+
export default defineComponent({
28+
compatConfig: { MODE: 3 },
29+
...optionOptions,
2730
});

components/vc-picker/RangePicker.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,11 @@ function RangerPicker<DateType>() {
331331

332332
// Fill disabled unit
333333
for (let i = 0; i < 2; i += 1) {
334-
if (mergedDisabled[i] && !getValue(postValues, i) && !getValue(props.allowEmpty, i)) {
334+
if (
335+
mergedDisabled.value[i] &&
336+
!getValue(postValues, i) &&
337+
!getValue(props.allowEmpty, i)
338+
) {
335339
postValues = updateValues(postValues, props.generateConfig.getNow(), i);
336340
}
337341
}

components/vc-select/BaseSelect.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -873,7 +873,7 @@ export default defineComponent({
873873
style={{
874874
width: 0,
875875
height: 0,
876-
display: 'flex',
876+
position: 'absolute',
877877
overflow: 'hidden',
878878
opacity: 0,
879879
}}

components/vc-table/Footer/Cell.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ export interface SummaryCellProps {
1313
}
1414

1515
export default defineComponent<SummaryCellProps>({
16-
name: 'SummaryCell',
16+
name: 'ATableSummaryCell',
1717
props: ['index', 'colSpan', 'rowSpan', 'align'] as any,
1818
setup(props, { attrs, slots }) {
1919
const tableContext = useInjectTable();

components/vc-table/Footer/Row.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { defineComponent } from 'vue';
22

33
export default defineComponent({
44
compatConfig: { MODE: 3 },
5-
name: 'FooterRow',
5+
name: 'ATableSummaryRow',
66
setup(_props, { slots }) {
77
return () => <tr>{slots.default?.()}</tr>;
88
},

components/vc-tree/TreeNode.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ const defaultTitle = '---';
2525

2626
export default defineComponent({
2727
compatConfig: { MODE: 3 },
28-
name: 'TreeNode',
28+
name: 'ATreeNode',
2929
inheritAttrs: false,
3030
props: treeNodeProps,
3131
isTreeNode: 1,

components/vc-virtual-list/List.tsx

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -225,8 +225,13 @@ const List = defineComponent({
225225
offset: undefined,
226226
});
227227
}
228+
if (componentRef.value) {
229+
state.scrollTop = componentRef.value.scrollTop;
230+
}
231+
},
232+
{
233+
immediate: true,
228234
},
229-
{ immediate: true },
230235
);
231236
watch(
232237
[
@@ -276,11 +281,11 @@ const List = defineComponent({
276281
itemTop = currentItemBottom;
277282
}
278283

279-
// Fallback to normal if not match. This code should never reach
280-
/* istanbul ignore next */
284+
// When scrollTop at the end but data cut to small count will reach this
281285
if (startIndex === undefined) {
282286
startIndex = 0;
283287
startOffset = 0;
288+
endIndex = Math.ceil(height / itemHeight);
284289
}
285290
if (endIndex === undefined) {
286291
endIndex = dataLen - 1;
@@ -324,7 +329,7 @@ const List = defineComponent({
324329
// When data size reduce. It may trigger native scroll event back to fit scroll position
325330
function onFallbackScroll(e: UIEvent) {
326331
const { scrollTop: newScrollTop } = e.currentTarget as Element;
327-
if (Math.abs(newScrollTop - state.scrollTop) >= 1) {
332+
if (newScrollTop !== state.scrollTop) {
328333
syncScrollTop(newScrollTop);
329334
}
330335

components/vc-virtual-list/ScrollBar.tsx

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -119,18 +119,19 @@ export default defineComponent({
119119
this.onScrollbarTouchStart,
120120
supportsPassive ? ({ passive: false } as EventListenerOptions) : false,
121121
);
122-
this.thumbRef.current.removeEventListener(
123-
'touchstart',
124-
this.onMouseDown,
125-
supportsPassive ? ({ passive: false } as EventListenerOptions) : false,
126-
);
127-
this.thumbRef.current.removeEventListener(
128-
'touchmove',
129-
this.onMouseMove,
130-
supportsPassive ? ({ passive: false } as EventListenerOptions) : false,
131-
);
132-
this.thumbRef.current.removeEventListener('touchend', this.onMouseUp);
133-
122+
if (this.thumbRef.current) {
123+
this.thumbRef.current.removeEventListener(
124+
'touchstart',
125+
this.onMouseDown,
126+
supportsPassive ? ({ passive: false } as EventListenerOptions) : false,
127+
);
128+
this.thumbRef.current.removeEventListener(
129+
'touchmove',
130+
this.onMouseMove,
131+
supportsPassive ? ({ passive: false } as EventListenerOptions) : false,
132+
);
133+
this.thumbRef.current.removeEventListener('touchend', this.onMouseUp);
134+
}
134135
raf.cancel(this.moveRaf);
135136
},
136137

0 commit comments

Comments
 (0)