@douyinfe/semi-foundation 2.7.1 → 2.8.0-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/datePicker/_utils/getDefaultPickerDate.ts +54 -0
- package/datePicker/datePicker.scss +2 -2
- package/form/form.scss +12 -4
- package/inputNumber/foundation.ts +1 -1
- package/lib/cjs/datePicker/_utils/getDefaultPickerDate.d.ts +15 -0
- package/lib/cjs/datePicker/_utils/getDefaultPickerDate.js +73 -0
- package/lib/cjs/datePicker/datePicker.css +14 -14
- package/lib/cjs/datePicker/datePicker.scss +2 -2
- package/lib/cjs/form/form.css +11 -2
- package/lib/cjs/form/form.scss +12 -4
- package/lib/cjs/inputNumber/foundation.js +1 -1
- package/lib/cjs/tooltip/foundation.d.ts +27 -1
- package/lib/cjs/tooltip/foundation.js +159 -3
- package/lib/cjs/utils/isEscPress.d.ts +4 -0
- package/lib/cjs/utils/isEscPress.js +22 -0
- package/lib/cjs/utils/keyCode.d.ts +1 -0
- package/lib/cjs/utils/keyCode.js +3 -1
- package/lib/es/datePicker/_utils/getDefaultPickerDate.d.ts +15 -0
- package/lib/es/datePicker/_utils/getDefaultPickerDate.js +57 -0
- package/lib/es/datePicker/datePicker.css +14 -14
- package/lib/es/datePicker/datePicker.scss +2 -2
- package/lib/es/form/form.css +11 -2
- package/lib/es/form/form.scss +12 -4
- package/lib/es/inputNumber/foundation.js +1 -1
- package/lib/es/tooltip/foundation.d.ts +27 -1
- package/lib/es/tooltip/foundation.js +159 -3
- package/lib/es/utils/isEscPress.d.ts +4 -0
- package/lib/es/utils/isEscPress.js +8 -0
- package/lib/es/utils/keyCode.d.ts +1 -0
- package/lib/es/utils/keyCode.js +1 -0
- package/package.json +3 -3
- package/tooltip/foundation.ts +131 -3
- package/utils/isEscPress.ts +8 -0
- package/utils/keyCode.ts +1 -0
package/lib/cjs/utils/keyCode.js
CHANGED
|
@@ -6,7 +6,7 @@ _Object$defineProperty(exports, "__esModule", {
|
|
|
6
6
|
value: true
|
|
7
7
|
});
|
|
8
8
|
|
|
9
|
-
exports.default = exports.TAB_KEY = exports.ENTER_KEY = void 0;
|
|
9
|
+
exports.default = exports.TAB_KEY = exports.ESC_KEY = exports.ENTER_KEY = void 0;
|
|
10
10
|
|
|
11
11
|
/**
|
|
12
12
|
* @ignore
|
|
@@ -542,5 +542,7 @@ const ENTER_KEY = 'Enter';
|
|
|
542
542
|
exports.ENTER_KEY = ENTER_KEY;
|
|
543
543
|
const TAB_KEY = 'Tab';
|
|
544
544
|
exports.TAB_KEY = TAB_KEY;
|
|
545
|
+
const ESC_KEY = 'Escape';
|
|
546
|
+
exports.ESC_KEY = ESC_KEY;
|
|
545
547
|
var _default = keyCode;
|
|
546
548
|
exports.default = _default;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { Locale as dateFnsLocale } from 'date-fns';
|
|
2
|
+
/**
|
|
3
|
+
* get left panel picker date and right panel picker date
|
|
4
|
+
*/
|
|
5
|
+
export default function getDefaultPickerDate(options: GetDefaultPickerValueDateOptions): {
|
|
6
|
+
nowDate: Date;
|
|
7
|
+
nextDate: Date;
|
|
8
|
+
};
|
|
9
|
+
declare type BaseValueType = string | number | Date;
|
|
10
|
+
interface GetDefaultPickerValueDateOptions {
|
|
11
|
+
defaultPickerValue?: BaseValueType | BaseValueType[];
|
|
12
|
+
format: string;
|
|
13
|
+
dateFnsLocale: dateFnsLocale;
|
|
14
|
+
}
|
|
15
|
+
export {};
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import _Array$isArray from "@babel/runtime-corejs3/core-js-stable/array/is-array";
|
|
2
|
+
import { addMonths } from 'date-fns';
|
|
3
|
+
import isValidDate from './isValidDate';
|
|
4
|
+
import { compatiableParse } from './parser';
|
|
5
|
+
import isTimestamp from './isTimestamp';
|
|
6
|
+
/**
|
|
7
|
+
* get left panel picker date and right panel picker date
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
export default function getDefaultPickerDate(options) {
|
|
11
|
+
const {
|
|
12
|
+
defaultPickerValue,
|
|
13
|
+
format,
|
|
14
|
+
dateFnsLocale
|
|
15
|
+
} = options;
|
|
16
|
+
let nowDate = _Array$isArray(defaultPickerValue) ? defaultPickerValue[0] : defaultPickerValue;
|
|
17
|
+
let nextDate = _Array$isArray(defaultPickerValue) ? defaultPickerValue[1] : undefined;
|
|
18
|
+
|
|
19
|
+
switch (true) {
|
|
20
|
+
case isValidDate(nowDate):
|
|
21
|
+
break;
|
|
22
|
+
|
|
23
|
+
case isTimestamp(nowDate):
|
|
24
|
+
nowDate = new Date(nowDate);
|
|
25
|
+
break;
|
|
26
|
+
|
|
27
|
+
case typeof nowDate === 'string':
|
|
28
|
+
nowDate = compatiableParse(nowDate, format, undefined, dateFnsLocale);
|
|
29
|
+
break;
|
|
30
|
+
|
|
31
|
+
default:
|
|
32
|
+
nowDate = new Date();
|
|
33
|
+
break;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
switch (true) {
|
|
37
|
+
case isValidDate(nextDate):
|
|
38
|
+
break;
|
|
39
|
+
|
|
40
|
+
case isTimestamp(nextDate):
|
|
41
|
+
nextDate = new Date(nextDate);
|
|
42
|
+
break;
|
|
43
|
+
|
|
44
|
+
case typeof nextDate === 'string':
|
|
45
|
+
nextDate = compatiableParse(nextDate, format, undefined, dateFnsLocale);
|
|
46
|
+
break;
|
|
47
|
+
|
|
48
|
+
default:
|
|
49
|
+
nextDate = addMonths(nowDate, 1);
|
|
50
|
+
break;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
return {
|
|
54
|
+
nowDate: nowDate,
|
|
55
|
+
nextDate: nextDate
|
|
56
|
+
};
|
|
57
|
+
}
|
|
@@ -30,22 +30,22 @@
|
|
|
30
30
|
.semi-datepicker-month-grid[x-type=date] .semi-datepicker-yam-showing {
|
|
31
31
|
min-height: 325px;
|
|
32
32
|
}
|
|
33
|
-
.semi-datepicker-month-grid[x-
|
|
34
|
-
.semi-datepicker-month-grid[x-
|
|
33
|
+
.semi-datepicker-month-grid[x-insetinput=true] .semi-datepicker-month-grid-left[x-open-type=year],
|
|
34
|
+
.semi-datepicker-month-grid[x-insetinput=true] .semi-datepicker-month-grid-right[x-open-type=year] {
|
|
35
35
|
min-height: 312px;
|
|
36
36
|
}
|
|
37
|
-
.semi-datepicker-month-grid[x-
|
|
38
|
-
.semi-datepicker-month-grid[x-
|
|
37
|
+
.semi-datepicker-month-grid[x-insetinput=true] .semi-datepicker-month-grid-left[x-open-type=time],
|
|
38
|
+
.semi-datepicker-month-grid[x-insetinput=true] .semi-datepicker-month-grid-right[x-open-type=time] {
|
|
39
39
|
min-height: 314px;
|
|
40
40
|
}
|
|
41
|
-
.semi-datepicker-month-grid[x-
|
|
41
|
+
.semi-datepicker-month-grid[x-insetinput=true] .semi-datepicker-navigation {
|
|
42
42
|
padding-top: 8px;
|
|
43
43
|
padding-bottom: 8px;
|
|
44
44
|
}
|
|
45
|
-
.semi-datepicker-month-grid[x-
|
|
45
|
+
.semi-datepicker-month-grid[x-insetinput=true] .semi-datepicker-tpk {
|
|
46
46
|
min-height: 100%;
|
|
47
47
|
}
|
|
48
|
-
.semi-datepicker-month-grid[x-
|
|
48
|
+
.semi-datepicker-month-grid[x-insetinput=true][x-type=dateTime] .semi-datepicker-yam, .semi-datepicker-month-grid[x-insetinput=true][x-type=dateTimeRange] .semi-datepicker-yam {
|
|
49
49
|
height: 100%;
|
|
50
50
|
}
|
|
51
51
|
.semi-datepicker-month-grid .semi-datepicker-yearmonth-header {
|
|
@@ -620,21 +620,21 @@
|
|
|
620
620
|
.semi-datepicker-compact .semi-datepicker-month-grid[x-panel-yearandmonth-open-type=left] .semi-datepicker-weeks, .semi-datepicker-compact .semi-datepicker-month-grid[x-panel-yearandmonth-open-type=right] .semi-datepicker-weeks {
|
|
621
621
|
min-height: 168px;
|
|
622
622
|
}
|
|
623
|
-
.semi-datepicker-compact .semi-datepicker-month-grid[x-
|
|
624
|
-
.semi-datepicker-compact .semi-datepicker-month-grid[x-
|
|
623
|
+
.semi-datepicker-compact .semi-datepicker-month-grid[x-insetinput=true] .semi-datepicker-month-grid-left[x-open-type=year],
|
|
624
|
+
.semi-datepicker-compact .semi-datepicker-month-grid[x-insetinput=true] .semi-datepicker-month-grid-right[x-open-type=year] {
|
|
625
625
|
min-height: 236px;
|
|
626
626
|
}
|
|
627
|
-
.semi-datepicker-compact .semi-datepicker-month-grid[x-
|
|
628
|
-
.semi-datepicker-compact .semi-datepicker-month-grid[x-
|
|
627
|
+
.semi-datepicker-compact .semi-datepicker-month-grid[x-insetinput=true] .semi-datepicker-month-grid-left[x-open-type=time],
|
|
628
|
+
.semi-datepicker-compact .semi-datepicker-month-grid[x-insetinput=true] .semi-datepicker-month-grid-right[x-open-type=time] {
|
|
629
629
|
min-height: 236px;
|
|
630
630
|
}
|
|
631
|
-
.semi-datepicker-compact .semi-datepicker-month-grid[x-
|
|
631
|
+
.semi-datepicker-compact .semi-datepicker-month-grid[x-insetinput=true] .semi-datepicker-yam-showing {
|
|
632
632
|
min-height: 236px;
|
|
633
633
|
}
|
|
634
|
-
.semi-datepicker-compact .semi-datepicker-month-grid[x-
|
|
634
|
+
.semi-datepicker-compact .semi-datepicker-month-grid[x-insetinput=true] .semi-datepicker-tpk {
|
|
635
635
|
min-height: 100%;
|
|
636
636
|
}
|
|
637
|
-
.semi-datepicker-compact .semi-datepicker-month-grid[x-
|
|
637
|
+
.semi-datepicker-compact .semi-datepicker-month-grid[x-insetinput=true][x-type=dateTime] .semi-datepicker-yam, .semi-datepicker-compact .semi-datepicker-month-grid[x-insetinput=true][x-type=dateTimeRange] .semi-datepicker-yam {
|
|
638
638
|
height: 100%;
|
|
639
639
|
}
|
|
640
640
|
.semi-datepicker-compact.semi-datepicker-panel-yam .semi-scrolllist {
|
|
@@ -46,7 +46,7 @@ $module: #{$prefix}-datepicker;
|
|
|
46
46
|
min-height: $height-datepicker_dateType_yamShowing_min;
|
|
47
47
|
}
|
|
48
48
|
|
|
49
|
-
&[x-
|
|
49
|
+
&[x-insetinput=true] {
|
|
50
50
|
.#{$module}-month-grid-left,
|
|
51
51
|
.#{$module}-month-grid-right {
|
|
52
52
|
&[x-open-type=year] {
|
|
@@ -928,7 +928,7 @@ $module: #{$prefix}-datepicker;
|
|
|
928
928
|
}
|
|
929
929
|
}
|
|
930
930
|
|
|
931
|
-
&[x-
|
|
931
|
+
&[x-insetinput=true] {
|
|
932
932
|
.#{$module}-month-grid-left,
|
|
933
933
|
.#{$module}-month-grid-right {
|
|
934
934
|
&[x-open-type=year] {
|
package/lib/es/form/form.css
CHANGED
|
@@ -52,11 +52,12 @@
|
|
|
52
52
|
.semi-form-field-label-disabled {
|
|
53
53
|
color: var(--semi-color-disabled-text);
|
|
54
54
|
}
|
|
55
|
-
.semi-form-field-label-with-extra .semi-form-field-label-text
|
|
56
|
-
.semi-form-field-label-with-extra .semi-form-field-label-extra {
|
|
55
|
+
.semi-form-field-label-with-extra .semi-form-field-label-text {
|
|
57
56
|
display: inline-block;
|
|
58
57
|
}
|
|
59
58
|
.semi-form-field-label-with-extra .semi-form-field-label-extra {
|
|
59
|
+
display: flex;
|
|
60
|
+
align-items: center;
|
|
60
61
|
margin-left: 4px;
|
|
61
62
|
}
|
|
62
63
|
.semi-form-field-label-required .semi-form-field-label-text::after {
|
|
@@ -97,6 +98,10 @@
|
|
|
97
98
|
padding-top: 4px;
|
|
98
99
|
padding-bottom: 4px;
|
|
99
100
|
}
|
|
101
|
+
.semi-form-field[x-label-pos=top] .semi-form-field-label-with-extra {
|
|
102
|
+
display: flex;
|
|
103
|
+
align-items: center;
|
|
104
|
+
}
|
|
100
105
|
.semi-form-field[x-label-pos=left] {
|
|
101
106
|
display: flex;
|
|
102
107
|
}
|
|
@@ -106,6 +111,10 @@
|
|
|
106
111
|
padding-top: 6px;
|
|
107
112
|
padding-bottom: 6px;
|
|
108
113
|
}
|
|
114
|
+
.semi-form-field[x-label-pos=left] .semi-form-field-label-with-extra {
|
|
115
|
+
display: flex;
|
|
116
|
+
align-items: center;
|
|
117
|
+
}
|
|
109
118
|
.semi-form-field[x-label-pos=left] .semi-checkboxGroup,
|
|
110
119
|
.semi-form-field[x-label-pos=left] .semi-radioGroup {
|
|
111
120
|
padding-top: 6px;
|
package/lib/es/form/form.scss
CHANGED
|
@@ -91,18 +91,18 @@ $rating: #{$prefix}-rating;
|
|
|
91
91
|
}
|
|
92
92
|
|
|
93
93
|
&-with-extra {
|
|
94
|
-
.#{$field}-label-text
|
|
95
|
-
.#{$field}-label-extra {
|
|
94
|
+
.#{$field}-label-text {
|
|
96
95
|
display: inline-block;
|
|
97
96
|
}
|
|
98
97
|
.#{$field}-label-extra {
|
|
98
|
+
display: flex;
|
|
99
|
+
align-items: center;
|
|
99
100
|
margin-left: $spacing-form_label_extra-marginLeft;
|
|
100
101
|
}
|
|
101
102
|
}
|
|
102
103
|
|
|
103
104
|
&-required {
|
|
104
105
|
.#{$field}-label-text {
|
|
105
|
-
|
|
106
106
|
&::after {
|
|
107
107
|
content: "*";
|
|
108
108
|
margin-left: $spacing-form_label_required-marginLeft;
|
|
@@ -156,6 +156,11 @@ $rating: #{$prefix}-rating;
|
|
|
156
156
|
padding-top: $spacing-form_label_posTop-paddingTop;
|
|
157
157
|
padding-bottom: $spacing-form_label_posTop-paddingBottom;
|
|
158
158
|
}
|
|
159
|
+
.#{$field}-label-with-extra {
|
|
160
|
+
display: flex;
|
|
161
|
+
align-items: center;
|
|
162
|
+
}
|
|
163
|
+
|
|
159
164
|
}
|
|
160
165
|
|
|
161
166
|
&[x-label-pos="left"] {
|
|
@@ -168,7 +173,10 @@ $rating: #{$prefix}-rating;
|
|
|
168
173
|
padding-top: $spacing-form_label-paddingTop;
|
|
169
174
|
padding-bottom: $spacing-form_label-paddingTop;
|
|
170
175
|
}
|
|
171
|
-
|
|
176
|
+
.#{$field}-label-with-extra {
|
|
177
|
+
display: flex;
|
|
178
|
+
align-items: center;
|
|
179
|
+
}
|
|
172
180
|
.#{$checkboxGroup},
|
|
173
181
|
.#{$radioGroup} {
|
|
174
182
|
padding-top: $spacing-form_label-paddingTop;
|
|
@@ -466,7 +466,7 @@ class InputNumberFoundation extends BaseFoundation {
|
|
|
466
466
|
_adjustPrec(num) {
|
|
467
467
|
const precision = this.getProp('precision');
|
|
468
468
|
|
|
469
|
-
if (typeof precision === 'number') {
|
|
469
|
+
if (typeof precision === 'number' && num !== '') {
|
|
470
470
|
num = Number(num).toFixed(precision);
|
|
471
471
|
}
|
|
472
472
|
|
|
@@ -25,6 +25,7 @@ export interface TooltipAdapter<P = Record<string, any>, S = Record<string, any>
|
|
|
25
25
|
click: string;
|
|
26
26
|
focus: string;
|
|
27
27
|
blur: string;
|
|
28
|
+
keydown: string;
|
|
28
29
|
};
|
|
29
30
|
registerTriggerEvent(...args: any[]): void;
|
|
30
31
|
getTriggerBounding(...args: any[]): DOMRect;
|
|
@@ -40,6 +41,12 @@ export interface TooltipAdapter<P = Record<string, any>, S = Record<string, any>
|
|
|
40
41
|
updateContainerPosition(): void;
|
|
41
42
|
updatePlacementAttr(placement: Position): void;
|
|
42
43
|
getContainerPosition(): string;
|
|
44
|
+
getFocusableElements(node: any): any[];
|
|
45
|
+
getActiveElement(): any;
|
|
46
|
+
getContainer(): any;
|
|
47
|
+
setInitialFocus(): void;
|
|
48
|
+
notifyEscKeydown(event: any): void;
|
|
49
|
+
getTriggerNode(): any;
|
|
43
50
|
}
|
|
44
51
|
export declare type Position = ArrayElement<typeof strings.POSITION_SET>;
|
|
45
52
|
export interface PopupContainerDOMRect extends DOMRectLikeType {
|
|
@@ -63,7 +70,9 @@ export default class Tooltip<P = Record<string, any>, S = Record<string, any>> e
|
|
|
63
70
|
_reversePos(position?: string, isVertical?: boolean): string;
|
|
64
71
|
clearDelayTimer(): void;
|
|
65
72
|
_generateEvent(types: ArrayElement<typeof strings.TRIGGER_SET>): {
|
|
66
|
-
triggerEventSet: {
|
|
73
|
+
triggerEventSet: {
|
|
74
|
+
[x: string]: (event: any) => void;
|
|
75
|
+
};
|
|
67
76
|
portalEventSet: {};
|
|
68
77
|
};
|
|
69
78
|
onResize: () => void;
|
|
@@ -96,4 +105,21 @@ export default class Tooltip<P = Record<string, any>, S = Record<string, any>> e
|
|
|
96
105
|
_bindScrollEvent(): void;
|
|
97
106
|
_unBindScrollEvent(): void;
|
|
98
107
|
_initContainerPosition(): void;
|
|
108
|
+
handleContainerKeydown: (event: any) => void;
|
|
109
|
+
_handleTriggerKeydown(event: any): void;
|
|
110
|
+
/**
|
|
111
|
+
* focus trigger
|
|
112
|
+
*
|
|
113
|
+
* when trigger is 'focus' or 'hover', onFocus is bind to show popup
|
|
114
|
+
* if we focus trigger, popup will show again
|
|
115
|
+
*
|
|
116
|
+
* 如果 trigger 是 focus 或者 hover,则它绑定了 onFocus,这里我们如果重新 focus 的话,popup 会再次打开
|
|
117
|
+
* 因此 returnFocusOnClose 只支持 click trigger
|
|
118
|
+
*/
|
|
119
|
+
_focusTrigger(): void;
|
|
120
|
+
_handleEscKeyDown(event: any): void;
|
|
121
|
+
_handleContainerTabKeyDown(focusableElements: any[], event: any): void;
|
|
122
|
+
_handleContainerShiftTabKeyDown(focusableElements: any[], event: any): void;
|
|
123
|
+
_handleTriggerArrowDownKeydown(focusableElements: any[], event: any): void;
|
|
124
|
+
_handleTriggerArrowUpKeydown(focusableElements: any[], event: any): void;
|
|
99
125
|
}
|
|
@@ -175,6 +175,42 @@ export default class Tooltip extends BaseFoundation {
|
|
|
175
175
|
}
|
|
176
176
|
};
|
|
177
177
|
|
|
178
|
+
this.handleContainerKeydown = event => {
|
|
179
|
+
const {
|
|
180
|
+
guardFocus,
|
|
181
|
+
closeOnEsc
|
|
182
|
+
} = this.getProps();
|
|
183
|
+
|
|
184
|
+
switch (event && event.key) {
|
|
185
|
+
case "Escape":
|
|
186
|
+
closeOnEsc && this._handleEscKeyDown(event);
|
|
187
|
+
break;
|
|
188
|
+
|
|
189
|
+
case "Tab":
|
|
190
|
+
if (guardFocus) {
|
|
191
|
+
const container = this._adapter.getContainer();
|
|
192
|
+
|
|
193
|
+
const focusableElements = this._adapter.getFocusableElements(container);
|
|
194
|
+
|
|
195
|
+
const focusableNum = focusableElements.length;
|
|
196
|
+
|
|
197
|
+
if (focusableNum) {
|
|
198
|
+
// Shift + Tab will move focus backward
|
|
199
|
+
if (event.shiftKey) {
|
|
200
|
+
this._handleContainerShiftTabKeyDown(focusableElements, event);
|
|
201
|
+
} else {
|
|
202
|
+
this._handleContainerTabKeyDown(focusableElements, event);
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
break;
|
|
208
|
+
|
|
209
|
+
default:
|
|
210
|
+
break;
|
|
211
|
+
}
|
|
212
|
+
};
|
|
213
|
+
|
|
178
214
|
this._timer = null;
|
|
179
215
|
}
|
|
180
216
|
|
|
@@ -272,7 +308,12 @@ export default class Tooltip extends BaseFoundation {
|
|
|
272
308
|
_generateEvent(types) {
|
|
273
309
|
const eventNames = this._adapter.getEventName();
|
|
274
310
|
|
|
275
|
-
const triggerEventSet = {
|
|
311
|
+
const triggerEventSet = {
|
|
312
|
+
// bind esc keydown on trigger for a11y
|
|
313
|
+
[eventNames.keydown]: event => {
|
|
314
|
+
this._handleTriggerKeydown(event);
|
|
315
|
+
}
|
|
316
|
+
};
|
|
276
317
|
let portalEventSet = {};
|
|
277
318
|
|
|
278
319
|
switch (types) {
|
|
@@ -308,6 +349,15 @@ export default class Tooltip extends BaseFoundation {
|
|
|
308
349
|
triggerEventSet[eventNames.mouseLeave] = () => {
|
|
309
350
|
// console.log(e);
|
|
310
351
|
this.delayHide(); // this.hide('trigger');
|
|
352
|
+
}; // bind focus to hover trigger for a11y
|
|
353
|
+
|
|
354
|
+
|
|
355
|
+
triggerEventSet[eventNames.focus] = () => {
|
|
356
|
+
this.delayShow();
|
|
357
|
+
};
|
|
358
|
+
|
|
359
|
+
triggerEventSet[eventNames.blur] = () => {
|
|
360
|
+
this.delayHide();
|
|
311
361
|
};
|
|
312
362
|
|
|
313
363
|
portalEventSet = _Object$assign({}, triggerEventSet);
|
|
@@ -331,7 +381,7 @@ export default class Tooltip extends BaseFoundation {
|
|
|
331
381
|
|
|
332
382
|
case 'custom':
|
|
333
383
|
// when trigger type is 'custom', no need to bind eventHandler
|
|
334
|
-
// show/hide completely
|
|
384
|
+
// show/hide completely depend on props.visible which change by user
|
|
335
385
|
break;
|
|
336
386
|
|
|
337
387
|
default:
|
|
@@ -357,7 +407,13 @@ export default class Tooltip extends BaseFoundation {
|
|
|
357
407
|
const nowVisible = this.getState('visible');
|
|
358
408
|
|
|
359
409
|
if (nowVisible !== isVisible) {
|
|
360
|
-
this._adapter.togglePortalVisible(isVisible, () =>
|
|
410
|
+
this._adapter.togglePortalVisible(isVisible, () => {
|
|
411
|
+
if (isVisible) {
|
|
412
|
+
this._adapter.setInitialFocus();
|
|
413
|
+
}
|
|
414
|
+
|
|
415
|
+
this._adapter.notifyVisibleChange(isVisible);
|
|
416
|
+
});
|
|
361
417
|
}
|
|
362
418
|
}
|
|
363
419
|
|
|
@@ -860,4 +916,104 @@ export default class Tooltip extends BaseFoundation {
|
|
|
860
916
|
this._adapter.updateContainerPosition();
|
|
861
917
|
}
|
|
862
918
|
|
|
919
|
+
_handleTriggerKeydown(event) {
|
|
920
|
+
const {
|
|
921
|
+
closeOnEsc
|
|
922
|
+
} = this.getProps();
|
|
923
|
+
|
|
924
|
+
const container = this._adapter.getContainer();
|
|
925
|
+
|
|
926
|
+
const focusableElements = this._adapter.getFocusableElements(container);
|
|
927
|
+
|
|
928
|
+
const focusableNum = focusableElements.length;
|
|
929
|
+
|
|
930
|
+
switch (event && event.key) {
|
|
931
|
+
case "Escape":
|
|
932
|
+
closeOnEsc && this._handleEscKeyDown(event);
|
|
933
|
+
break;
|
|
934
|
+
|
|
935
|
+
case "ArrowUp":
|
|
936
|
+
focusableNum && this._handleTriggerArrowUpKeydown(focusableElements, event);
|
|
937
|
+
break;
|
|
938
|
+
|
|
939
|
+
case "ArrowDown":
|
|
940
|
+
focusableNum && this._handleTriggerArrowDownKeydown(focusableElements, event);
|
|
941
|
+
break;
|
|
942
|
+
|
|
943
|
+
default:
|
|
944
|
+
break;
|
|
945
|
+
}
|
|
946
|
+
}
|
|
947
|
+
/**
|
|
948
|
+
* focus trigger
|
|
949
|
+
*
|
|
950
|
+
* when trigger is 'focus' or 'hover', onFocus is bind to show popup
|
|
951
|
+
* if we focus trigger, popup will show again
|
|
952
|
+
*
|
|
953
|
+
* 如果 trigger 是 focus 或者 hover,则它绑定了 onFocus,这里我们如果重新 focus 的话,popup 会再次打开
|
|
954
|
+
* 因此 returnFocusOnClose 只支持 click trigger
|
|
955
|
+
*/
|
|
956
|
+
|
|
957
|
+
|
|
958
|
+
_focusTrigger() {
|
|
959
|
+
const {
|
|
960
|
+
trigger,
|
|
961
|
+
returnFocusOnClose
|
|
962
|
+
} = this.getProps();
|
|
963
|
+
|
|
964
|
+
if (returnFocusOnClose && trigger === 'click') {
|
|
965
|
+
const triggerNode = this._adapter.getTriggerNode();
|
|
966
|
+
|
|
967
|
+
if (triggerNode && 'focus' in triggerNode) {
|
|
968
|
+
triggerNode.focus();
|
|
969
|
+
}
|
|
970
|
+
}
|
|
971
|
+
}
|
|
972
|
+
|
|
973
|
+
_handleEscKeyDown(event) {
|
|
974
|
+
const {
|
|
975
|
+
trigger
|
|
976
|
+
} = this.getProps();
|
|
977
|
+
|
|
978
|
+
if (trigger !== 'custom') {
|
|
979
|
+
this.hide();
|
|
980
|
+
|
|
981
|
+
this._focusTrigger();
|
|
982
|
+
}
|
|
983
|
+
|
|
984
|
+
this._adapter.notifyEscKeydown(event);
|
|
985
|
+
}
|
|
986
|
+
|
|
987
|
+
_handleContainerTabKeyDown(focusableElements, event) {
|
|
988
|
+
const activeElement = this._adapter.getActiveElement();
|
|
989
|
+
|
|
990
|
+
const isLastCurrentFocus = focusableElements[focusableElements.length - 1] === activeElement;
|
|
991
|
+
|
|
992
|
+
if (isLastCurrentFocus) {
|
|
993
|
+
focusableElements[0].focus();
|
|
994
|
+
event.preventDefault(); // prevent browser default tab move behavior
|
|
995
|
+
}
|
|
996
|
+
}
|
|
997
|
+
|
|
998
|
+
_handleContainerShiftTabKeyDown(focusableElements, event) {
|
|
999
|
+
const activeElement = this._adapter.getActiveElement();
|
|
1000
|
+
|
|
1001
|
+
const isFirstCurrentFocus = focusableElements[0] === activeElement;
|
|
1002
|
+
|
|
1003
|
+
if (isFirstCurrentFocus) {
|
|
1004
|
+
focusableElements[focusableElements.length - 1].focus();
|
|
1005
|
+
event.preventDefault(); // prevent browser default tab move behavior
|
|
1006
|
+
}
|
|
1007
|
+
}
|
|
1008
|
+
|
|
1009
|
+
_handleTriggerArrowDownKeydown(focusableElements, event) {
|
|
1010
|
+
focusableElements[0].focus();
|
|
1011
|
+
event.preventDefault(); // prevent browser default scroll behavior
|
|
1012
|
+
}
|
|
1013
|
+
|
|
1014
|
+
_handleTriggerArrowUpKeydown(focusableElements, event) {
|
|
1015
|
+
focusableElements[focusableElements.length - 1].focus();
|
|
1016
|
+
event.preventDefault(); // prevent browser default scroll behavior
|
|
1017
|
+
}
|
|
1018
|
+
|
|
863
1019
|
}
|
package/lib/es/utils/keyCode.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@douyinfe/semi-foundation",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.8.0-beta.0",
|
|
4
4
|
"description": "",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"build:lib": "node ./scripts/compileLib.js",
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
},
|
|
9
9
|
"dependencies": {
|
|
10
10
|
"@babel/runtime-corejs3": "^7.15.4",
|
|
11
|
-
"@douyinfe/semi-animation": "2.
|
|
11
|
+
"@douyinfe/semi-animation": "2.8.0-beta.0",
|
|
12
12
|
"async-validator": "^3.5.0",
|
|
13
13
|
"classnames": "^2.2.6",
|
|
14
14
|
"date-fns": "^2.9.0",
|
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
"*.scss",
|
|
25
25
|
"*.css"
|
|
26
26
|
],
|
|
27
|
-
"gitHead": "
|
|
27
|
+
"gitHead": "05140034ad843d6a8d3a4a205e71f02b429f78fe",
|
|
28
28
|
"devDependencies": {
|
|
29
29
|
"@babel/plugin-proposal-decorators": "^7.15.8",
|
|
30
30
|
"@babel/plugin-transform-runtime": "^7.15.8",
|