@douyinfe/semi-foundation 2.30.0-beta.0 → 2.30.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.
@@ -92,6 +92,7 @@
92
92
  }
93
93
  .semi-select:focus {
94
94
  border: 1px solid var(--semi-color-focus-border);
95
+ background-color: var(--semi-color-fill-0);
95
96
  outline: 0;
96
97
  }
97
98
  .semi-select-small {
@@ -36,6 +36,7 @@ $overflowList: #{$prefix}-overflow-list;
36
36
 
37
37
  &:focus {
38
38
  border: $width-select-border-focus solid $color-select-border-focus;
39
+ background-color: $color-select-bg-focus;
39
40
  outline: 0;
40
41
  }
41
42
 
@@ -2,6 +2,7 @@
2
2
  $color-select-bg-default: var(--semi-color-fill-0); // 选择器输入框背景色 - 默认态
3
3
  $color-select-bg-hover: var(--semi-color-fill-1); // 选择器输入框背景色 - 悬停态
4
4
  $color-select-bg-active: var(--semi-color-fill-2); // 选择器输入框背景色 - 按下态
5
+ $color-select-bg-focus: var(--semi-color-fill-0); // 选择器输入框背景色 - 聚焦态
5
6
  $color-select-border-default: transparent; // 选择器输入框描边颜色
6
7
  $color-select-border-hover: $color-select-border-default; // 选择器输入框描边颜色 - 悬浮
7
8
  $color-select-border-active: var(--semi-color-focus-border); // 选择器输入框描边颜色 - 按下态
@@ -521,6 +521,9 @@ class Tooltip extends _foundation.default {
521
521
  spacing,
522
522
  isOverFlow
523
523
  } = props;
524
+ const {
525
+ innerWidth
526
+ } = window;
524
527
  const triggerRect = ((0, _isEmpty2.default)(props.triggerRect) ? props.triggerRect : this._adapter.getTriggerBounding()) || Object.assign({}, defaultRect);
525
528
  const containerRect = ((0, _isEmpty2.default)(props.containerRect) ? props.containerRect : this._adapter.getPopupContainerRect()) || Object.assign({}, defaultRect);
526
529
  const wrapperRect = ((0, _isEmpty2.default)(props.wrapperRect) ? props.wrapperRect : this._adapter.getWrapperBounding()) || Object.assign({}, defaultRect); // eslint-disable-next-line
@@ -559,6 +562,7 @@ class Tooltip extends _foundation.default {
559
562
  const isWidthOverFlow = isOverFlow && isOverFlow[1];
560
563
  const isTriggerNearLeft = middleX - containerRect.left < containerRect.right - middleX;
561
564
  const isTriggerNearTop = middleY - containerRect.top < containerRect.bottom - middleY;
565
+ const isWrapperWidthOverflow = wrapperRect.width > innerWidth;
562
566
 
563
567
  switch (position) {
564
568
  case 'top':
@@ -573,7 +577,7 @@ class Tooltip extends _foundation.default {
573
577
  case 'topLeft':
574
578
  // left = pointAtCenter ? middleX - offsetXWithArrow : triggerRect.left;
575
579
  // top = triggerRect.top - SPACING;
576
- left = isWidthOverFlow ? containerRect.left : pointAtCenter ? middleX - offsetXWithArrow : triggerRect.left;
580
+ left = isWidthOverFlow ? isWrapperWidthOverflow ? containerRect.left : containerRect.right - wrapperRect.width : pointAtCenter ? middleX - offsetXWithArrow : triggerRect.left;
577
581
  top = isHeightOverFlow ? containerRect.bottom + offsetHeight : triggerRect.top - SPACING;
578
582
  translateY = -1;
579
583
  break;
@@ -625,7 +629,7 @@ class Tooltip extends _foundation.default {
625
629
  case 'bottomLeft':
626
630
  // left = pointAtCenter ? middleX - offsetXWithArrow : triggerRect.left;
627
631
  // top = triggerRect.bottom + SPACING;
628
- left = isWidthOverFlow ? containerRect.left : pointAtCenter ? middleX - offsetXWithArrow : triggerRect.left;
632
+ left = isWidthOverFlow ? isWrapperWidthOverflow ? containerRect.left : containerRect.right - wrapperRect.width : pointAtCenter ? middleX - offsetXWithArrow : triggerRect.left;
629
633
  top = isHeightOverFlow ? containerRect.top + offsetYWithArrow - SPACING : triggerRect.top + triggerRect.height + SPACING;
630
634
  break;
631
635
 
@@ -27,7 +27,7 @@ export interface BasicOnChange {
27
27
  (node: BasicTreeNodeData[] | BasicTreeNodeData, e: any): void;
28
28
  (value: BasicTreeNodeData['value'] | Array<BasicTreeNodeData['value']>, node: BasicTreeNodeData[] | BasicTreeNodeData, e: any): void;
29
29
  }
30
- export interface BasicTreeSelectProps extends Pick<BasicTreeProps, 'virtualize' | 'renderFullLabel' | 'renderLabel' | 'autoExpandParent' | 'className' | 'defaultExpandAll' | 'defaultExpandedKeys' | 'defaultValue' | 'disabled' | 'emptyContent' | 'expandAction' | 'expandedKeys' | 'filterTreeNode' | 'labelEllipsis' | 'leafOnly' | 'multiple' | 'onChangeWithObject' | 'showClear' | 'showFilteredOnly' | 'style' | 'treeData' | 'treeNodeFilterProp' | 'value' | 'onExpand' | 'expandAll' | 'disableStrictly' | 'aria-label' | 'checkRelation'> {
30
+ export interface BasicTreeSelectProps extends Pick<BasicTreeProps, 'virtualize' | 'renderFullLabel' | 'renderLabel' | 'autoExpandParent' | 'className' | 'defaultExpandAll' | 'defaultExpandedKeys' | 'defaultValue' | 'disabled' | 'emptyContent' | 'expandAction' | 'expandedKeys' | 'filterTreeNode' | 'labelEllipsis' | 'leafOnly' | 'multiple' | 'onChangeWithObject' | 'showClear' | 'showFilteredOnly' | 'style' | 'treeData' | 'treeNodeFilterProp' | 'value' | 'onExpand' | 'expandAll' | 'disableStrictly' | 'aria-label' | 'checkRelation' | 'preventScroll'> {
31
31
  motion?: Motion;
32
32
  mouseEnterDelay?: number;
33
33
  mouseLeaveDelay?: number;
@@ -74,7 +74,6 @@ export interface BasicTreeSelectProps extends Pick<BasicTreeProps, 'virtualize'
74
74
  export interface BasicTreeSelectInnerData extends Pick<BasicTreeInnerData, 'keyEntities' | 'treeData' | 'flattenNodes' | 'selectedKeys' | 'checkedKeys' | 'halfCheckedKeys' | 'motionKeys' | 'motionType' | 'expandedKeys' | 'filteredKeys' | 'filteredExpandedKeys' | 'filteredShownKeys' | 'cachedKeyValuePairs' | 'inputValue' | 'disabledKeys' | 'loadedKeys' | 'loadingKeys' | 'realCheckedKeys'> {
75
75
  inputTriggerFocus: boolean;
76
76
  isOpen: boolean;
77
- isInput: boolean;
78
77
  rePosKey: number;
79
78
  dropdownMinWidth: null | number;
80
79
  isHovering: boolean;
@@ -102,6 +101,7 @@ export interface TreeSelectAdapter<P = Record<string, any>, S = Record<string, a
102
101
  notifyLoad: (newLoadedKeys: Set<string>, data: BasicTreeNodeData) => void;
103
102
  updateInputFocus: (bool: boolean) => void;
104
103
  updateLoadKeys: (data: BasicTreeNodeData, resolve: (value?: any) => void) => void;
104
+ updateIsFocus: (bool: boolean) => void;
105
105
  }
106
106
  export default class TreeSelectFoundation<P = Record<string, any>, S = Record<string, any>> extends BaseFoundation<TreeSelectAdapter<P, S>, P, S> {
107
107
  constructor(adapter: TreeSelectAdapter<P, S>);
@@ -131,8 +131,11 @@ export default class TreeSelectFoundation<P = Record<string, any>, S = Record<st
131
131
  focusInput(bool: boolean): void;
132
132
  _notifyMultipleChange(key: string[], e: any): void;
133
133
  _notifyChange(key: any, e: any): void;
134
+ _registerClickOutsideHandler: (e: any) => void;
134
135
  _notifyFocus(e: any): void;
136
+ handleTriggerFocus(e: any): void;
135
137
  _notifyBlur(e: any): void;
138
+ handlerTriggerBlur(e: any): void;
136
139
  toggleHoverState(bool: boolean): void;
137
140
  open(): void;
138
141
  close(e: any): void;
@@ -35,6 +35,13 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
35
35
  class TreeSelectFoundation extends _foundation.default {
36
36
  constructor(adapter) {
37
37
  super(Object.assign({}, adapter));
38
+
39
+ this._registerClickOutsideHandler = e => {
40
+ this._adapter.registerClickOutsideHandler(e => {
41
+ this.handlerTriggerBlur(e);
42
+ this.close(e);
43
+ });
44
+ };
38
45
  }
39
46
 
40
47
  init() {
@@ -53,6 +60,10 @@ class TreeSelectFoundation extends _foundation.default {
53
60
  if (isOpen) {
54
61
  this.open();
55
62
  }
63
+
64
+ if (triggerSearchAutoFocus) {
65
+ this.handleTriggerFocus(null);
66
+ }
56
67
  }
57
68
 
58
69
  destroy() {
@@ -320,6 +331,14 @@ class TreeSelectFoundation extends _foundation.default {
320
331
 
321
332
  _notifyFocus(e) {
322
333
  this._adapter.notifyFocus(e);
334
+ }
335
+
336
+ handleTriggerFocus(e) {
337
+ this._adapter.updateIsFocus(true);
338
+
339
+ this._notifyFocus(e);
340
+
341
+ this._registerClickOutsideHandler(e);
323
342
  } // Scenes that may trigger blur
324
343
  // 1、clickOutSide
325
344
  // 2、click option / press enter, and then select complete(when multiple is false
@@ -330,6 +349,14 @@ class TreeSelectFoundation extends _foundation.default {
330
349
  this._adapter.notifyBlur(e);
331
350
  }
332
351
 
352
+ handlerTriggerBlur(e) {
353
+ this._adapter.updateIsFocus(false);
354
+
355
+ this._notifyBlur(e);
356
+
357
+ this._adapter.unregisterClickOutsideHandler();
358
+ }
359
+
333
360
  toggleHoverState(bool) {
334
361
  this._adapter.toggleHovering(bool);
335
362
  }
@@ -338,19 +365,11 @@ class TreeSelectFoundation extends _foundation.default {
338
365
  this._adapter.openMenu();
339
366
 
340
367
  this._setDropdownWidth();
341
-
342
- this._adapter.registerClickOutsideHandler(e => {
343
- this.close(e);
344
- });
345
368
  }
346
369
 
347
370
  close(e) {
348
371
  this._adapter.closeMenu();
349
372
 
350
- this._adapter.unregisterClickOutsideHandler();
351
-
352
- this._notifyBlur(e);
353
-
354
373
  if (this.getProp('motionExpand')) {
355
374
  this._adapter.updateState({
356
375
  motionKeys: new Set([])
@@ -363,7 +382,8 @@ class TreeSelectFoundation extends _foundation.default {
363
382
 
364
383
  const {
365
384
  isOpen,
366
- inputValue
385
+ inputValue,
386
+ isFocus
367
387
  } = this.getStates();
368
388
  const {
369
389
  searchPosition
@@ -371,16 +391,20 @@ class TreeSelectFoundation extends _foundation.default {
371
391
 
372
392
  if (isDisabled) {
373
393
  return;
374
- } else if (!isOpen) {
375
- this.open();
376
-
377
- this._notifyFocus(e);
378
- } else if (isOpen) {
379
- if (searchPosition === 'trigger' && inputValue) {
380
- return;
394
+ } else {
395
+ if (!isFocus) {
396
+ this.handleTriggerFocus(e);
381
397
  }
382
398
 
383
- this.close(e);
399
+ if (isOpen) {
400
+ if (searchPosition === 'trigger' && inputValue) {
401
+ return;
402
+ }
403
+
404
+ this.close(e);
405
+ } else {
406
+ this.open();
407
+ }
384
408
  }
385
409
  }
386
410
  /**
@@ -626,6 +650,7 @@ class TreeSelectFoundation extends _foundation.default {
626
650
 
627
651
  if (clickToHide && (this._isSelectToClose() || !data.children)) {
628
652
  this.close(e);
653
+ this.handlerTriggerBlur(e);
629
654
  }
630
655
  }
631
656
 
@@ -17,12 +17,16 @@
17
17
  }
18
18
  .semi-tree-select:hover {
19
19
  background-color: var(--semi-color-fill-1);
20
- border: 1px solid inherit;
20
+ border: 1px solid transparent;
21
21
  }
22
22
  .semi-tree-select-focus {
23
23
  border: 1px solid var(--semi-color-focus-border);
24
24
  outline: 0;
25
25
  }
26
+ .semi-tree-select-focus:hover {
27
+ border: 1px solid var(--semi-color-focus-border);
28
+ outline: 0;
29
+ }
26
30
  .semi-tree-select-warning {
27
31
  background-color: var(--semi-color-warning-light-default);
28
32
  border-color: var(--semi-color-warning-light-default);
@@ -26,6 +26,12 @@ $module: #{$prefix}-tree-select;
26
26
  outline: 0;
27
27
  }
28
28
 
29
+ &-focus:hover {
30
+ border: $width-treeSelect_focus-border solid $color-treeSelect_default-border-focus;
31
+ outline: 0;
32
+ }
33
+
34
+
29
35
  &-warning {
30
36
  background-color: $color-treeSelect_warning-bg-default;
31
37
  border-color: $color-treeSelect_warning-border-default;
@@ -6,7 +6,7 @@ $color-treeSelect_default-icon-hover: var(--semi-color-primary-hover); // 树选
6
6
  $color-treeSelect_default-icon-active: var(--semi-color-primary-active); // 树选择器选择框清空按钮颜色 - 按下
7
7
  $color-treeSelect_default-bg-hover: var(--semi-color-fill-1); // 树选择器选择框背景颜色 - 悬停
8
8
 
9
- $color-treeSelect_default-border-hover: inherit; // 树选择器选择框描边颜色 - 悬浮
9
+ $color-treeSelect_default-border-hover: transparent; // 树选择器选择框描边颜色 - 悬浮
10
10
  $color-treeSelect_default-border-focus: var(--semi-color-focus-border);// 树选择器选择框描边颜色 - 选中
11
11
 
12
12
  $color-treeSelect_search-border-default: var(--semi-color-fill-0); // 树选择器菜单搜索框描边颜色 - 默认
@@ -92,6 +92,7 @@
92
92
  }
93
93
  .semi-select:focus {
94
94
  border: 1px solid var(--semi-color-focus-border);
95
+ background-color: var(--semi-color-fill-0);
95
96
  outline: 0;
96
97
  }
97
98
  .semi-select-small {
@@ -36,6 +36,7 @@ $overflowList: #{$prefix}-overflow-list;
36
36
 
37
37
  &:focus {
38
38
  border: $width-select-border-focus solid $color-select-border-focus;
39
+ background-color: $color-select-bg-focus;
39
40
  outline: 0;
40
41
  }
41
42
 
@@ -2,6 +2,7 @@
2
2
  $color-select-bg-default: var(--semi-color-fill-0); // 选择器输入框背景色 - 默认态
3
3
  $color-select-bg-hover: var(--semi-color-fill-1); // 选择器输入框背景色 - 悬停态
4
4
  $color-select-bg-active: var(--semi-color-fill-2); // 选择器输入框背景色 - 按下态
5
+ $color-select-bg-focus: var(--semi-color-fill-0); // 选择器输入框背景色 - 聚焦态
5
6
  $color-select-border-default: transparent; // 选择器输入框描边颜色
6
7
  $color-select-border-hover: $color-select-border-default; // 选择器输入框描边颜色 - 悬浮
7
8
  $color-select-border-active: var(--semi-color-focus-border); // 选择器输入框描边颜色 - 按下态
@@ -507,6 +507,9 @@ export default class Tooltip extends BaseFoundation {
507
507
  spacing,
508
508
  isOverFlow
509
509
  } = props;
510
+ const {
511
+ innerWidth
512
+ } = window;
510
513
  const triggerRect = (_isEmpty(props.triggerRect) ? props.triggerRect : this._adapter.getTriggerBounding()) || Object.assign({}, defaultRect);
511
514
  const containerRect = (_isEmpty(props.containerRect) ? props.containerRect : this._adapter.getPopupContainerRect()) || Object.assign({}, defaultRect);
512
515
  const wrapperRect = (_isEmpty(props.wrapperRect) ? props.wrapperRect : this._adapter.getWrapperBounding()) || Object.assign({}, defaultRect); // eslint-disable-next-line
@@ -549,6 +552,7 @@ export default class Tooltip extends BaseFoundation {
549
552
  const isWidthOverFlow = isOverFlow && isOverFlow[1];
550
553
  const isTriggerNearLeft = middleX - containerRect.left < containerRect.right - middleX;
551
554
  const isTriggerNearTop = middleY - containerRect.top < containerRect.bottom - middleY;
555
+ const isWrapperWidthOverflow = wrapperRect.width > innerWidth;
552
556
 
553
557
  switch (position) {
554
558
  case 'top':
@@ -563,7 +567,7 @@ export default class Tooltip extends BaseFoundation {
563
567
  case 'topLeft':
564
568
  // left = pointAtCenter ? middleX - offsetXWithArrow : triggerRect.left;
565
569
  // top = triggerRect.top - SPACING;
566
- left = isWidthOverFlow ? containerRect.left : pointAtCenter ? middleX - offsetXWithArrow : triggerRect.left;
570
+ left = isWidthOverFlow ? isWrapperWidthOverflow ? containerRect.left : containerRect.right - wrapperRect.width : pointAtCenter ? middleX - offsetXWithArrow : triggerRect.left;
567
571
  top = isHeightOverFlow ? containerRect.bottom + offsetHeight : triggerRect.top - SPACING;
568
572
  translateY = -1;
569
573
  break;
@@ -615,7 +619,7 @@ export default class Tooltip extends BaseFoundation {
615
619
  case 'bottomLeft':
616
620
  // left = pointAtCenter ? middleX - offsetXWithArrow : triggerRect.left;
617
621
  // top = triggerRect.bottom + SPACING;
618
- left = isWidthOverFlow ? containerRect.left : pointAtCenter ? middleX - offsetXWithArrow : triggerRect.left;
622
+ left = isWidthOverFlow ? isWrapperWidthOverflow ? containerRect.left : containerRect.right - wrapperRect.width : pointAtCenter ? middleX - offsetXWithArrow : triggerRect.left;
619
623
  top = isHeightOverFlow ? containerRect.top + offsetYWithArrow - SPACING : triggerRect.top + triggerRect.height + SPACING;
620
624
  break;
621
625
 
@@ -27,7 +27,7 @@ export interface BasicOnChange {
27
27
  (node: BasicTreeNodeData[] | BasicTreeNodeData, e: any): void;
28
28
  (value: BasicTreeNodeData['value'] | Array<BasicTreeNodeData['value']>, node: BasicTreeNodeData[] | BasicTreeNodeData, e: any): void;
29
29
  }
30
- export interface BasicTreeSelectProps extends Pick<BasicTreeProps, 'virtualize' | 'renderFullLabel' | 'renderLabel' | 'autoExpandParent' | 'className' | 'defaultExpandAll' | 'defaultExpandedKeys' | 'defaultValue' | 'disabled' | 'emptyContent' | 'expandAction' | 'expandedKeys' | 'filterTreeNode' | 'labelEllipsis' | 'leafOnly' | 'multiple' | 'onChangeWithObject' | 'showClear' | 'showFilteredOnly' | 'style' | 'treeData' | 'treeNodeFilterProp' | 'value' | 'onExpand' | 'expandAll' | 'disableStrictly' | 'aria-label' | 'checkRelation'> {
30
+ export interface BasicTreeSelectProps extends Pick<BasicTreeProps, 'virtualize' | 'renderFullLabel' | 'renderLabel' | 'autoExpandParent' | 'className' | 'defaultExpandAll' | 'defaultExpandedKeys' | 'defaultValue' | 'disabled' | 'emptyContent' | 'expandAction' | 'expandedKeys' | 'filterTreeNode' | 'labelEllipsis' | 'leafOnly' | 'multiple' | 'onChangeWithObject' | 'showClear' | 'showFilteredOnly' | 'style' | 'treeData' | 'treeNodeFilterProp' | 'value' | 'onExpand' | 'expandAll' | 'disableStrictly' | 'aria-label' | 'checkRelation' | 'preventScroll'> {
31
31
  motion?: Motion;
32
32
  mouseEnterDelay?: number;
33
33
  mouseLeaveDelay?: number;
@@ -74,7 +74,6 @@ export interface BasicTreeSelectProps extends Pick<BasicTreeProps, 'virtualize'
74
74
  export interface BasicTreeSelectInnerData extends Pick<BasicTreeInnerData, 'keyEntities' | 'treeData' | 'flattenNodes' | 'selectedKeys' | 'checkedKeys' | 'halfCheckedKeys' | 'motionKeys' | 'motionType' | 'expandedKeys' | 'filteredKeys' | 'filteredExpandedKeys' | 'filteredShownKeys' | 'cachedKeyValuePairs' | 'inputValue' | 'disabledKeys' | 'loadedKeys' | 'loadingKeys' | 'realCheckedKeys'> {
75
75
  inputTriggerFocus: boolean;
76
76
  isOpen: boolean;
77
- isInput: boolean;
78
77
  rePosKey: number;
79
78
  dropdownMinWidth: null | number;
80
79
  isHovering: boolean;
@@ -102,6 +101,7 @@ export interface TreeSelectAdapter<P = Record<string, any>, S = Record<string, a
102
101
  notifyLoad: (newLoadedKeys: Set<string>, data: BasicTreeNodeData) => void;
103
102
  updateInputFocus: (bool: boolean) => void;
104
103
  updateLoadKeys: (data: BasicTreeNodeData, resolve: (value?: any) => void) => void;
104
+ updateIsFocus: (bool: boolean) => void;
105
105
  }
106
106
  export default class TreeSelectFoundation<P = Record<string, any>, S = Record<string, any>> extends BaseFoundation<TreeSelectAdapter<P, S>, P, S> {
107
107
  constructor(adapter: TreeSelectAdapter<P, S>);
@@ -131,8 +131,11 @@ export default class TreeSelectFoundation<P = Record<string, any>, S = Record<st
131
131
  focusInput(bool: boolean): void;
132
132
  _notifyMultipleChange(key: string[], e: any): void;
133
133
  _notifyChange(key: any, e: any): void;
134
+ _registerClickOutsideHandler: (e: any) => void;
134
135
  _notifyFocus(e: any): void;
136
+ handleTriggerFocus(e: any): void;
135
137
  _notifyBlur(e: any): void;
138
+ handlerTriggerBlur(e: any): void;
136
139
  toggleHoverState(bool: boolean): void;
137
140
  open(): void;
138
141
  close(e: any): void;
@@ -14,6 +14,13 @@ import isEnterPress from '../utils/isEnterPress'; // eslint-disable-next-line ma
14
14
  export default class TreeSelectFoundation extends BaseFoundation {
15
15
  constructor(adapter) {
16
16
  super(Object.assign({}, adapter));
17
+
18
+ this._registerClickOutsideHandler = e => {
19
+ this._adapter.registerClickOutsideHandler(e => {
20
+ this.handlerTriggerBlur(e);
21
+ this.close(e);
22
+ });
23
+ };
17
24
  }
18
25
 
19
26
  init() {
@@ -32,6 +39,10 @@ export default class TreeSelectFoundation extends BaseFoundation {
32
39
  if (isOpen) {
33
40
  this.open();
34
41
  }
42
+
43
+ if (triggerSearchAutoFocus) {
44
+ this.handleTriggerFocus(null);
45
+ }
35
46
  }
36
47
 
37
48
  destroy() {
@@ -299,6 +310,14 @@ export default class TreeSelectFoundation extends BaseFoundation {
299
310
 
300
311
  _notifyFocus(e) {
301
312
  this._adapter.notifyFocus(e);
313
+ }
314
+
315
+ handleTriggerFocus(e) {
316
+ this._adapter.updateIsFocus(true);
317
+
318
+ this._notifyFocus(e);
319
+
320
+ this._registerClickOutsideHandler(e);
302
321
  } // Scenes that may trigger blur
303
322
  // 1、clickOutSide
304
323
  // 2、click option / press enter, and then select complete(when multiple is false
@@ -309,6 +328,14 @@ export default class TreeSelectFoundation extends BaseFoundation {
309
328
  this._adapter.notifyBlur(e);
310
329
  }
311
330
 
331
+ handlerTriggerBlur(e) {
332
+ this._adapter.updateIsFocus(false);
333
+
334
+ this._notifyBlur(e);
335
+
336
+ this._adapter.unregisterClickOutsideHandler();
337
+ }
338
+
312
339
  toggleHoverState(bool) {
313
340
  this._adapter.toggleHovering(bool);
314
341
  }
@@ -317,19 +344,11 @@ export default class TreeSelectFoundation extends BaseFoundation {
317
344
  this._adapter.openMenu();
318
345
 
319
346
  this._setDropdownWidth();
320
-
321
- this._adapter.registerClickOutsideHandler(e => {
322
- this.close(e);
323
- });
324
347
  }
325
348
 
326
349
  close(e) {
327
350
  this._adapter.closeMenu();
328
351
 
329
- this._adapter.unregisterClickOutsideHandler();
330
-
331
- this._notifyBlur(e);
332
-
333
352
  if (this.getProp('motionExpand')) {
334
353
  this._adapter.updateState({
335
354
  motionKeys: new Set([])
@@ -342,7 +361,8 @@ export default class TreeSelectFoundation extends BaseFoundation {
342
361
 
343
362
  const {
344
363
  isOpen,
345
- inputValue
364
+ inputValue,
365
+ isFocus
346
366
  } = this.getStates();
347
367
  const {
348
368
  searchPosition
@@ -350,16 +370,20 @@ export default class TreeSelectFoundation extends BaseFoundation {
350
370
 
351
371
  if (isDisabled) {
352
372
  return;
353
- } else if (!isOpen) {
354
- this.open();
355
-
356
- this._notifyFocus(e);
357
- } else if (isOpen) {
358
- if (searchPosition === 'trigger' && inputValue) {
359
- return;
373
+ } else {
374
+ if (!isFocus) {
375
+ this.handleTriggerFocus(e);
360
376
  }
361
377
 
362
- this.close(e);
378
+ if (isOpen) {
379
+ if (searchPosition === 'trigger' && inputValue) {
380
+ return;
381
+ }
382
+
383
+ this.close(e);
384
+ } else {
385
+ this.open();
386
+ }
363
387
  }
364
388
  }
365
389
  /**
@@ -605,6 +629,7 @@ export default class TreeSelectFoundation extends BaseFoundation {
605
629
 
606
630
  if (clickToHide && (this._isSelectToClose() || !data.children)) {
607
631
  this.close(e);
632
+ this.handlerTriggerBlur(e);
608
633
  }
609
634
  }
610
635
 
@@ -17,12 +17,16 @@
17
17
  }
18
18
  .semi-tree-select:hover {
19
19
  background-color: var(--semi-color-fill-1);
20
- border: 1px solid inherit;
20
+ border: 1px solid transparent;
21
21
  }
22
22
  .semi-tree-select-focus {
23
23
  border: 1px solid var(--semi-color-focus-border);
24
24
  outline: 0;
25
25
  }
26
+ .semi-tree-select-focus:hover {
27
+ border: 1px solid var(--semi-color-focus-border);
28
+ outline: 0;
29
+ }
26
30
  .semi-tree-select-warning {
27
31
  background-color: var(--semi-color-warning-light-default);
28
32
  border-color: var(--semi-color-warning-light-default);
@@ -26,6 +26,12 @@ $module: #{$prefix}-tree-select;
26
26
  outline: 0;
27
27
  }
28
28
 
29
+ &-focus:hover {
30
+ border: $width-treeSelect_focus-border solid $color-treeSelect_default-border-focus;
31
+ outline: 0;
32
+ }
33
+
34
+
29
35
  &-warning {
30
36
  background-color: $color-treeSelect_warning-bg-default;
31
37
  border-color: $color-treeSelect_warning-border-default;
@@ -6,7 +6,7 @@ $color-treeSelect_default-icon-hover: var(--semi-color-primary-hover); // 树选
6
6
  $color-treeSelect_default-icon-active: var(--semi-color-primary-active); // 树选择器选择框清空按钮颜色 - 按下
7
7
  $color-treeSelect_default-bg-hover: var(--semi-color-fill-1); // 树选择器选择框背景颜色 - 悬停
8
8
 
9
- $color-treeSelect_default-border-hover: inherit; // 树选择器选择框描边颜色 - 悬浮
9
+ $color-treeSelect_default-border-hover: transparent; // 树选择器选择框描边颜色 - 悬浮
10
10
  $color-treeSelect_default-border-focus: var(--semi-color-focus-border);// 树选择器选择框描边颜色 - 选中
11
11
 
12
12
  $color-treeSelect_search-border-default: var(--semi-color-fill-0); // 树选择器菜单搜索框描边颜色 - 默认
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@douyinfe/semi-foundation",
3
- "version": "2.30.0-beta.0",
3
+ "version": "2.30.0",
4
4
  "description": "",
5
5
  "scripts": {
6
6
  "build:lib": "export NODE_OPTIONS=--no-experimental-fetch && node ./scripts/compileLib.js",
@@ -23,7 +23,7 @@
23
23
  "*.scss",
24
24
  "*.css"
25
25
  ],
26
- "gitHead": "330e8cf3c8bced4dee7d5c77c7e3931a0f40376b",
26
+ "gitHead": "c433ecebd974f8bb013a030b22d9a22cb8e70e9e",
27
27
  "devDependencies": {
28
28
  "@babel/plugin-transform-runtime": "^7.15.8",
29
29
  "@babel/preset-env": "^7.15.8",
@@ -36,6 +36,7 @@ $overflowList: #{$prefix}-overflow-list;
36
36
 
37
37
  &:focus {
38
38
  border: $width-select-border-focus solid $color-select-border-focus;
39
+ background-color: $color-select-bg-focus;
39
40
  outline: 0;
40
41
  }
41
42
 
@@ -2,6 +2,7 @@
2
2
  $color-select-bg-default: var(--semi-color-fill-0); // 选择器输入框背景色 - 默认态
3
3
  $color-select-bg-hover: var(--semi-color-fill-1); // 选择器输入框背景色 - 悬停态
4
4
  $color-select-bg-active: var(--semi-color-fill-2); // 选择器输入框背景色 - 按下态
5
+ $color-select-bg-focus: var(--semi-color-fill-0); // 选择器输入框背景色 - 聚焦态
5
6
  $color-select-border-default: transparent; // 选择器输入框描边颜色
6
7
  $color-select-border-hover: $color-select-border-default; // 选择器输入框描边颜色 - 悬浮
7
8
  $color-select-border-active: var(--semi-color-focus-border); // 选择器输入框描边颜色 - 按下态
@@ -387,6 +387,8 @@ export default class Tooltip<P = Record<string, any>, S = Record<string, any>> e
387
387
 
388
388
  calcPosStyle(props: {triggerRect: DOMRect; wrapperRect: DOMRect; containerRect: PopupContainerDOMRect; position?: Position; spacing?: number; isOverFlow?: [boolean, boolean]}) {
389
389
  const { spacing, isOverFlow } = props;
390
+ const { innerWidth } = window;
391
+
390
392
  const triggerRect = (isEmpty(props.triggerRect) ? props.triggerRect : this._adapter.getTriggerBounding()) || { ...defaultRect as any };
391
393
  const containerRect = (isEmpty(props.containerRect) ? props.containerRect : this._adapter.getPopupContainerRect()) || {
392
394
  ...defaultRect,
@@ -427,7 +429,8 @@ export default class Tooltip<P = Record<string, any>, S = Record<string, any>> e
427
429
 
428
430
  const isTriggerNearLeft = middleX - containerRect.left < containerRect.right - middleX;
429
431
  const isTriggerNearTop = middleY - containerRect.top < containerRect.bottom - middleY;
430
-
432
+
433
+ const isWrapperWidthOverflow = wrapperRect.width > innerWidth;
431
434
 
432
435
  switch (position) {
433
436
  case 'top':
@@ -441,7 +444,7 @@ export default class Tooltip<P = Record<string, any>, S = Record<string, any>> e
441
444
  case 'topLeft':
442
445
  // left = pointAtCenter ? middleX - offsetXWithArrow : triggerRect.left;
443
446
  // top = triggerRect.top - SPACING;
444
- left = isWidthOverFlow ? containerRect.left : (pointAtCenter ? middleX - offsetXWithArrow : triggerRect.left);
447
+ left = isWidthOverFlow ? (isWrapperWidthOverflow ? containerRect.left : containerRect.right - wrapperRect.width ) : (pointAtCenter ? middleX - offsetXWithArrow : triggerRect.left);
445
448
  top = isHeightOverFlow ? containerRect.bottom + offsetHeight : triggerRect.top - SPACING;
446
449
  translateY = -1;
447
450
  break;
@@ -487,7 +490,7 @@ export default class Tooltip<P = Record<string, any>, S = Record<string, any>> e
487
490
  case 'bottomLeft':
488
491
  // left = pointAtCenter ? middleX - offsetXWithArrow : triggerRect.left;
489
492
  // top = triggerRect.bottom + SPACING;
490
- left = isWidthOverFlow ? containerRect.left : (pointAtCenter ? middleX - offsetXWithArrow : triggerRect.left);
493
+ left = isWidthOverFlow ? (isWrapperWidthOverflow ? containerRect.left : containerRect.right - wrapperRect.width ) : (pointAtCenter ? middleX - offsetXWithArrow : triggerRect.left);
491
494
  top = isHeightOverFlow ? containerRect.top + offsetYWithArrow - SPACING : triggerRect.top + triggerRect.height + SPACING;
492
495
  break;
493
496
  case 'bottomRight':
@@ -95,6 +95,7 @@ export interface BasicTreeSelectProps extends Pick<BasicTreeProps,
95
95
  | 'disableStrictly'
96
96
  | 'aria-label'
97
97
  | 'checkRelation'
98
+ | 'preventScroll'
98
99
  > {
99
100
  motion?: Motion;
100
101
  mouseEnterDelay?: number;
@@ -163,7 +164,7 @@ export interface BasicTreeSelectInnerData extends Pick<BasicTreeInnerData,
163
164
  > {
164
165
  inputTriggerFocus: boolean;
165
166
  isOpen: boolean;
166
- isInput: boolean;
167
+ // isInput: boolean;
167
168
  rePosKey: number;
168
169
  dropdownMinWidth: null | number;
169
170
  isHovering: boolean;
@@ -191,7 +192,8 @@ export interface TreeSelectAdapter<P = Record<string, any>, S = Record<string, a
191
192
  toggleHovering: (bool: boolean) => void;
192
193
  notifyLoad: (newLoadedKeys: Set<string>, data: BasicTreeNodeData) => void;
193
194
  updateInputFocus: (bool: boolean) => void;
194
- updateLoadKeys: (data: BasicTreeNodeData, resolve: (value?: any) => void) => void
195
+ updateLoadKeys: (data: BasicTreeNodeData, resolve: (value?: any) => void) => void;
196
+ updateIsFocus: (bool: boolean) => void
195
197
  }
196
198
 
197
199
  // eslint-disable-next-line max-len
@@ -210,6 +212,9 @@ export default class TreeSelectFoundation<P = Record<string, any>, S = Record<st
210
212
  if (isOpen) {
211
213
  this.open();
212
214
  }
215
+ if (triggerSearchAutoFocus) {
216
+ this.handleTriggerFocus(null);
217
+ }
213
218
  }
214
219
 
215
220
  destroy() {
@@ -424,12 +429,25 @@ export default class TreeSelectFoundation<P = Record<string, any>, S = Record<st
424
429
  }
425
430
  }
426
431
 
432
+ _registerClickOutsideHandler = (e) => {
433
+ this._adapter.registerClickOutsideHandler(e => {
434
+ this.handlerTriggerBlur(e);
435
+ this.close(e);
436
+ });
437
+ }
438
+
427
439
  // Scenes that may trigger focus:
428
440
  // 1、click selection
429
441
  _notifyFocus(e: any) {
430
442
  this._adapter.notifyFocus(e);
431
443
  }
432
444
 
445
+ handleTriggerFocus(e: any) {
446
+ this._adapter.updateIsFocus(true);
447
+ this._notifyFocus(e);
448
+ this._registerClickOutsideHandler(e);
449
+ }
450
+
433
451
  // Scenes that may trigger blur
434
452
  // 1、clickOutSide
435
453
  // 2、click option / press enter, and then select complete(when multiple is false
@@ -438,6 +456,12 @@ export default class TreeSelectFoundation<P = Record<string, any>, S = Record<st
438
456
  this._adapter.notifyBlur(e);
439
457
  }
440
458
 
459
+ handlerTriggerBlur(e) {
460
+ this._adapter.updateIsFocus(false);
461
+ this._notifyBlur(e);
462
+ this._adapter.unregisterClickOutsideHandler();
463
+ }
464
+
441
465
  toggleHoverState(bool: boolean) {
442
466
  this._adapter.toggleHovering(bool);
443
467
  }
@@ -445,15 +469,10 @@ export default class TreeSelectFoundation<P = Record<string, any>, S = Record<st
445
469
  open() {
446
470
  this._adapter.openMenu();
447
471
  this._setDropdownWidth();
448
- this._adapter.registerClickOutsideHandler(e => {
449
- this.close(e);
450
- });
451
472
  }
452
473
 
453
474
  close(e: any) {
454
475
  this._adapter.closeMenu();
455
- this._adapter.unregisterClickOutsideHandler();
456
- this._notifyBlur(e);
457
476
  if (this.getProp('motionExpand')) {
458
477
  this._adapter.updateState({ motionKeys: new Set([]) });
459
478
  }
@@ -461,18 +480,22 @@ export default class TreeSelectFoundation<P = Record<string, any>, S = Record<st
461
480
 
462
481
  handleClick(e: any) {
463
482
  const isDisabled = this._isDisabled();
464
- const { isOpen, inputValue } = this.getStates();
483
+ const { isOpen, inputValue, isFocus } = this.getStates();
465
484
  const { searchPosition } = this.getProps();
466
485
  if (isDisabled) {
467
486
  return;
468
- } else if (!isOpen) {
469
- this.open();
470
- this._notifyFocus(e);
471
- } else if (isOpen) {
472
- if (searchPosition === 'trigger' && inputValue) {
473
- return;
487
+ } else {
488
+ if (!isFocus) {
489
+ this.handleTriggerFocus(e);
490
+ }
491
+ if (isOpen) {
492
+ if (searchPosition === 'trigger' && inputValue) {
493
+ return;
494
+ }
495
+ this.close(e);
496
+ } else {
497
+ this.open();
474
498
  }
475
- this.close(e);
476
499
  }
477
500
  }
478
501
 
@@ -639,6 +662,7 @@ export default class TreeSelectFoundation<P = Record<string, any>, S = Record<st
639
662
  }
640
663
  if (clickToHide && (this._isSelectToClose() || !data.children)) {
641
664
  this.close(e);
665
+ this.handlerTriggerBlur(e);
642
666
  }
643
667
  }
644
668
 
@@ -26,6 +26,12 @@ $module: #{$prefix}-tree-select;
26
26
  outline: 0;
27
27
  }
28
28
 
29
+ &-focus:hover {
30
+ border: $width-treeSelect_focus-border solid $color-treeSelect_default-border-focus;
31
+ outline: 0;
32
+ }
33
+
34
+
29
35
  &-warning {
30
36
  background-color: $color-treeSelect_warning-bg-default;
31
37
  border-color: $color-treeSelect_warning-border-default;
@@ -6,7 +6,7 @@ $color-treeSelect_default-icon-hover: var(--semi-color-primary-hover); // 树选
6
6
  $color-treeSelect_default-icon-active: var(--semi-color-primary-active); // 树选择器选择框清空按钮颜色 - 按下
7
7
  $color-treeSelect_default-bg-hover: var(--semi-color-fill-1); // 树选择器选择框背景颜色 - 悬停
8
8
 
9
- $color-treeSelect_default-border-hover: inherit; // 树选择器选择框描边颜色 - 悬浮
9
+ $color-treeSelect_default-border-hover: transparent; // 树选择器选择框描边颜色 - 悬浮
10
10
  $color-treeSelect_default-border-focus: var(--semi-color-focus-border);// 树选择器选择框描边颜色 - 选中
11
11
 
12
12
  $color-treeSelect_search-border-default: var(--semi-color-fill-0); // 树选择器菜单搜索框描边颜色 - 默认