@douyinfe/semi-foundation 2.15.2-alpha.0 → 2.16.1

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.
Files changed (59) hide show
  1. package/dropdown/menuFoundation.ts +4 -2
  2. package/input/input.scss +44 -9
  3. package/input/textarea.scss +2 -2
  4. package/lib/cjs/dropdown/menuFoundation.js +6 -3
  5. package/lib/cjs/input/input.css +32 -1
  6. package/lib/cjs/input/input.scss +44 -9
  7. package/lib/cjs/input/textarea.css +2 -2
  8. package/lib/cjs/input/textarea.scss +2 -2
  9. package/lib/cjs/radio/radio.css +75 -20
  10. package/lib/cjs/radio/radio.scss +36 -22
  11. package/lib/cjs/radio/rtl.scss +47 -0
  12. package/lib/cjs/select/select.css +2 -2
  13. package/lib/cjs/select/variables.scss +4 -4
  14. package/lib/cjs/slider/foundation.d.ts +9 -2
  15. package/lib/cjs/slider/foundation.js +195 -5
  16. package/lib/cjs/slider/slider.css +3 -0
  17. package/lib/cjs/slider/slider.scss +7 -5
  18. package/lib/cjs/slider/variables.scss +4 -4
  19. package/lib/cjs/switch/switch.css +2 -2
  20. package/lib/cjs/switch/switch.scss +2 -2
  21. package/lib/cjs/timePicker/foundation.d.ts +1 -1
  22. package/lib/cjs/timePicker/foundation.js +1 -1
  23. package/lib/cjs/tooltip/variables.scss +1 -1
  24. package/lib/cjs/treeSelect/treeSelect.css +2 -0
  25. package/lib/cjs/treeSelect/treeSelect.scss +2 -0
  26. package/lib/es/dropdown/menuFoundation.js +6 -3
  27. package/lib/es/input/input.css +32 -1
  28. package/lib/es/input/input.scss +44 -9
  29. package/lib/es/input/textarea.css +2 -2
  30. package/lib/es/input/textarea.scss +2 -2
  31. package/lib/es/radio/radio.css +75 -20
  32. package/lib/es/radio/radio.scss +36 -22
  33. package/lib/es/radio/rtl.scss +47 -0
  34. package/lib/es/select/select.css +2 -2
  35. package/lib/es/select/variables.scss +4 -4
  36. package/lib/es/slider/foundation.d.ts +9 -2
  37. package/lib/es/slider/foundation.js +192 -5
  38. package/lib/es/slider/slider.css +3 -0
  39. package/lib/es/slider/slider.scss +7 -5
  40. package/lib/es/slider/variables.scss +4 -4
  41. package/lib/es/switch/switch.css +2 -2
  42. package/lib/es/switch/switch.scss +2 -2
  43. package/lib/es/timePicker/foundation.d.ts +1 -1
  44. package/lib/es/timePicker/foundation.js +1 -1
  45. package/lib/es/tooltip/variables.scss +1 -1
  46. package/lib/es/treeSelect/treeSelect.css +2 -0
  47. package/lib/es/treeSelect/treeSelect.scss +2 -0
  48. package/package.json +2 -2
  49. package/radio/radio.scss +36 -22
  50. package/radio/rtl.scss +47 -0
  51. package/select/variables.scss +4 -4
  52. package/slider/foundation.ts +141 -9
  53. package/slider/slider.scss +7 -5
  54. package/slider/variables.scss +4 -4
  55. package/switch/switch.scss +2 -2
  56. package/timePicker/foundation.ts +1 -1
  57. package/tooltip/variables.scss +1 -1
  58. package/treeSelect/treeSelect.scss +2 -0
  59. package/utils/a11y.ts +2 -2
@@ -58,16 +58,16 @@ $width-select_arrow: 32px; // 选择器输入框下拉箭头宽度
58
58
  $width-select_arrow_empty: 12px; // 选择器输入框下拉箭头为空时(有suffix icon)宽度
59
59
  $width-select_clear-icon: 32px; // 选择器输入框清空按钮宽度
60
60
  $width-select_group_top-border: $border-thickness-control; // 选择器菜单分组标题描边宽度
61
- $height-select_multiple_content_wrapper-minHeight: $height-select_default - 2; // 多项选择器标签组最小宽度
61
+ $height-select_multiple_content_wrapper-minHeight: $height-select_default - 2px; // 多项选择器标签组最小宽度
62
62
  $width-select-border-hover: $width-select-border; // 选择器输入框描边宽度 - 悬浮
63
63
  $width-select-border-focus: $width-select-border-hover; // 选择器输入框描边宽度 - 按下
64
64
  $width-select-border-active: $width-select-border-focus; // 选择器输入框描边宽度 - 选中
65
65
  // Spacing
66
66
  $spacing-select_option_tick-marginRight: $spacing-tight; // 选择器菜单选中对勾右侧外边距
67
67
  $spacing-select_prefix_suffix_text-marginX: $spacing-base-tight; // 选择器输入框前后缀文本水平内边距
68
- $spacing-select_prefix_suffix_text-marginY: 0; // 选择器输入框前后缀文本垂直内边距
68
+ $spacing-select_prefix_suffix_text-marginY: 0px; // 选择器输入框前后缀文本垂直内边距
69
69
  $spacing-select_prefix_suffix_icon-marginX: $spacing-tight; // 选择器输入框前后缀图标水平内边距
70
- $spacing-select_prefix_suffix_icon-marginY: 0; // 选择器输入框前后缀图标垂直内边距
70
+ $spacing-select_prefix_suffix_icon-marginY: 0px; // 选择器输入框前后缀图标垂直内边距
71
71
  $spacing-select_create_tips-marginRight: $spacing-extra-tight; // 创建新选项右侧外边距
72
72
  $spacing-select_group-marginTop: $spacing-extra-tight; // 选择器菜单分组标题顶部外边距
73
73
  $spacing-select_group-paddingTop: $spacing-base-tight; // 选择器菜单分组标题顶部内边距
@@ -106,5 +106,5 @@ $font-select_inset_label-fontWeight: 600; // 选择器内嵌标签文本字重
106
106
  $font-select_keyword-fontWeight: 600; // 选择器搜索结果命关键词中文本字重
107
107
 
108
108
  // Other
109
- $opacity-select_selection_text_inactive: .4;
109
+ $opacity-select_selection_text_inactive: 0.4;
110
110
 
@@ -3,7 +3,8 @@
3
3
  /* eslint-disable no-nested-ternary */
4
4
  import BaseFoundation, { DefaultAdapter } from '../base/foundation';
5
5
  import touchEventPolyfill from '../utils/touchPolyfill';
6
-
6
+ import warning from '../utils/warning';
7
+ import { handlePrevent } from '../utils/a11y';
7
8
 
8
9
  export interface Marks{
9
10
  [key: number]: string;
@@ -34,7 +35,7 @@ export interface SliderProps{
34
35
  'aria-label'?: string;
35
36
  'aria-labelledby'?: string;
36
37
  'aria-valuetext'?: string;
37
- getAriaValueText?: (value: number) => string;
38
+ getAriaValueText?: (value: number, index?: number) => string;
38
39
  }
39
40
 
40
41
  export interface SliderState {
@@ -49,6 +50,8 @@ export interface SliderState {
49
50
  clickValue: 0;
50
51
  showBoundary: boolean;
51
52
  isInRenderTree: boolean;
53
+ firstDotFocusVisible: boolean;
54
+ secondDotFocusVisible: boolean;
52
55
  }
53
56
 
54
57
  export interface SliderLengths{
@@ -65,7 +68,6 @@ export interface ScrollParentVal{
65
68
 
66
69
  export interface OverallVars{
67
70
  dragging: boolean[];
68
- chooseMovePos: 'min' | 'max';
69
71
  }
70
72
 
71
73
  export interface SliderAdapter extends DefaultAdapter<SliderProps, SliderState>{
@@ -514,8 +516,7 @@ export default class SliderFoundation extends BaseFoundation<SliderAdapter> {
514
516
  const handleMinDom = this._adapter.getMinHandleEl().current;
515
517
  const handleMaxDom = this._adapter.getMaxHandleEl().current;
516
518
  if (e.target === handleMinDom || e.target === handleMaxDom) {
517
- e.preventDefault();
518
- e.stopPropagation();
519
+ handlePrevent(e);
519
520
  const touch = touchEventPolyfill(e.touches[0], e);
520
521
  this.onHandleDown(touch, handler);
521
522
  }
@@ -564,14 +565,147 @@ export default class SliderFoundation extends BaseFoundation<SliderAdapter> {
564
565
  this._adapter.setDragging([dragging[0], false]);
565
566
  }
566
567
  this._adapter.setStateVal('isDrag', false);
567
- // this._adapter.setStateVal('chooseMovePos', '');
568
568
  this._adapter.onHandleLeave();
569
569
  this._adapter.onHandleUpAfter();
570
570
  return true;
571
571
  };
572
572
 
573
+ _handleValueDecreaseWithKeyBoard = (step: number, handler: 'min'| 'max') => {
574
+ const { min, currentValue } = this.getStates();
575
+ const { range } = this.getProps();
576
+ if (handler === 'min') {
577
+ if (range) {
578
+ let newMinValue = currentValue[0] - step;
579
+ newMinValue = newMinValue < min ? min : newMinValue;
580
+ return [newMinValue, currentValue[1]];
581
+ } else {
582
+ let newMinValue = currentValue - step;
583
+ newMinValue = newMinValue < min ? min : newMinValue;
584
+ return newMinValue;
585
+ }
586
+ } else {
587
+ let newMaxValue = currentValue[1] - step;
588
+ newMaxValue = newMaxValue < currentValue[0] ? currentValue[0] : newMaxValue;
589
+ return [currentValue[0], newMaxValue];
590
+ }
591
+ }
592
+
593
+ _handleValueIncreaseWithKeyBoard = (step: number, handler: 'min'| 'max') => {
594
+ const { max, currentValue } = this.getStates();
595
+ const { range } = this.getProps();
596
+ if (handler === 'min') {
597
+ if (range) {
598
+ let newMinValue = currentValue[0] + step;
599
+ newMinValue = newMinValue > currentValue[1] ? currentValue[1] : newMinValue;
600
+ return [newMinValue, currentValue[1]];
601
+ } else {
602
+ let newMinValue = currentValue + step;
603
+ newMinValue = newMinValue > max ? max : newMinValue;
604
+ return newMinValue;
605
+ }
606
+ } else {
607
+ let newMaxValue = currentValue[1] + step;
608
+ newMaxValue = newMaxValue > max ? max : newMaxValue;
609
+ return [currentValue[0], newMaxValue];
610
+ }
611
+ }
612
+
613
+ _handleHomeKey = (handler: 'min'| 'max') => {
614
+ const { min, currentValue } = this.getStates();
615
+ const { range } = this.getProps();
616
+ if (handler === 'min') {
617
+ if (range) {
618
+ return [min, currentValue[1]];
619
+ } else {
620
+ return min;
621
+ }
622
+ } else {
623
+ return [currentValue[0], currentValue[0]];
624
+ }
625
+ }
626
+
627
+ _handleEndKey = (handler: 'min'| 'max') => {
628
+ const { max, currentValue } = this.getStates();
629
+ const { range } = this.getProps();
630
+ if (handler === 'min') {
631
+ if (range) {
632
+ return [currentValue[1], currentValue[1]];
633
+ } else {
634
+ return max;
635
+ }
636
+ } else {
637
+ return [currentValue[0], max];
638
+ }
639
+ }
640
+
641
+ handleKeyDown = (event: any, handler: 'min'| 'max') => {
642
+ const { min, max, currentValue } = this.getStates();
643
+ const { step, range } = this.getProps();
644
+ let outputValue;
645
+ switch (event.key) {
646
+ case "ArrowLeft":
647
+ case "ArrowDown":
648
+ outputValue = this._handleValueDecreaseWithKeyBoard(step, handler);
649
+ break;
650
+ case "ArrowRight":
651
+ case "ArrowUp":
652
+ outputValue = this._handleValueIncreaseWithKeyBoard(step, handler);
653
+ break;
654
+ case "PageUp":
655
+ outputValue = this._handleValueIncreaseWithKeyBoard(10 * step, handler);
656
+ break;
657
+ case "PageDown":
658
+ outputValue = this._handleValueDecreaseWithKeyBoard(10 * step, handler);
659
+ break;
660
+ case "Home":
661
+ outputValue = this._handleHomeKey(handler);
662
+ break;
663
+ case "End":
664
+ outputValue = this._handleEndKey(handler);
665
+ break;
666
+ case 'default':
667
+ break;
668
+ }
669
+ if (["ArrowLeft", "ArrowDown", "ArrowRight", "ArrowUp", "PageUp", "PageDown", "Home", "End"].includes(event.key)) {
670
+ let update = true;
671
+ if (Array.isArray(currentValue)) {
672
+ update = !(currentValue[0] === outputValue[0] && currentValue[1] === outputValue[1]);
673
+ } else {
674
+ update = currentValue !== outputValue;
675
+ }
676
+ if (update) {
677
+ this._adapter.updateCurrentValue(outputValue);
678
+ this._adapter.notifyChange(outputValue);
679
+ }
680
+ handlePrevent(event);
681
+ }
682
+ }
683
+
573
684
  // eslint-disable-next-line @typescript-eslint/no-empty-function
574
- onFocus = (e:any, handler: 'min'| 'max') => {}
685
+ onFocus = (e: any, handler: 'min'| 'max') => {
686
+ handlePrevent(e);
687
+ const { target } = e;
688
+ try {
689
+ if (target.matches(':focus-visible')) {
690
+ if (handler === 'min') {
691
+ this._adapter.setStateVal('firstDotFocusVisible', true);
692
+ } else {
693
+ this._adapter.setStateVal('secondDotFocusVisible', true);
694
+ }
695
+ }
696
+ } catch (error) {
697
+ warning(true, 'Warning: [Semi Slider] The current browser does not support the focus-visible');
698
+ }
699
+ }
700
+
701
+ onBlur = (e: any, handler: 'min'| 'max') => {
702
+ const { firstDotFocusVisible, secondDotFocusVisible } = this.getStates();
703
+ if (handler === 'min') {
704
+ firstDotFocusVisible && this._adapter.setStateVal('firstDotFocusVisible', false);
705
+ } else {
706
+ secondDotFocusVisible && this._adapter.setStateVal('secondDotFocusVisible', false);
707
+ }
708
+ }
575
709
 
576
710
  handleWrapClick = (e: any) => {
577
711
  const { disabled, isDrag } = this._adapter.getStates();
@@ -648,6 +782,4 @@ export default class SliderFoundation extends BaseFoundation<SliderAdapter> {
648
782
  return vertical ? y : x;
649
783
  }
650
784
 
651
-
652
-
653
785
  }
@@ -1,5 +1,5 @@
1
1
  //@import '../theme/variables.scss';
2
- @import "./variables.scss";
2
+ @import './variables.scss';
3
3
 
4
4
  $module: #{$prefix}-slider;
5
5
 
@@ -29,7 +29,7 @@ $module: #{$prefix}-slider;
29
29
  font-variant: tabular-nums;
30
30
  line-height: $font-slider_rail-lineHeight;
31
31
  list-style: none;
32
- font-feature-settings: "tnum";
32
+ font-feature-settings: 'tnum';
33
33
  position: absolute;
34
34
  height: $height-slider_rail;
35
35
  cursor: pointer;
@@ -54,7 +54,11 @@ $module: #{$prefix}-slider;
54
54
  border: none;
55
55
  border-radius: 50%;
56
56
  cursor: pointer;
57
- transition: #fff .3s;
57
+ transition: #fff 0.3s;
58
+
59
+ &:focus-visible {
60
+ outline: $width-slider_handle-focus solid $color-slider_handle-focus;
61
+ }
58
62
  }
59
63
 
60
64
  &-handle:hover {
@@ -133,10 +137,8 @@ $module: #{$prefix}-slider;
133
137
  text-align: center;
134
138
  cursor: pointer;
135
139
  transform: translate(-50%, 0) rotate(-180deg);
136
-
137
140
  }
138
141
 
139
-
140
142
  &-boundary {
141
143
  position: relative;
142
144
  font-size: $font-size-small;
@@ -11,9 +11,10 @@ $color-slider_handle_disabled-border-hover: var(--semi-color-white); // 禁用
11
11
  $color-slider_handle_disabled-border: var(--semi-color-border); // 禁用滑动条圆形描边颜色 - 默认态
12
12
  $color-slider_mark-text-default: var(--semi-color-text-2); // 滑动条刻度文字颜色
13
13
  $color-slider_rail-bg-default: var(--semi-color-fill-0); // 滑动条轨道颜色 - 未填充
14
- $color-slider_rail: rgba(0, 0, 0, .65);
14
+ $color-slider_rail: rgba(0, 0, 0, 0.65);
15
15
  $color-slider_track-bg-default: var(--semi-color-primary); // 滑动条轨道颜色 - 已填充
16
16
  $color-slider_track_disabled-bg: var(--semi-color-primary-disabled); // 禁用滑动条轨道颜色 - 已填充
17
+ $color-slider_handle-focus: var(--semi-color-primary-light-active); // 圆形按钮轮廓 - 聚焦
17
18
 
18
19
  // Spacing
19
20
  $spacing-slider-paddingX: 13px; // 滑动条整体水平内边距
@@ -33,7 +34,7 @@ $spacing-slider_boundary_min-left: 0;
33
34
  $spacing-slider_boundary_max-right: 0;
34
35
  $spacing-slider_vertical_marks-marginTop: -30px; // 垂直滑动条刻度标签顶部外边距
35
36
  $spacing-slider_vertical_marks-marginLeft: 29px; // 垂直滑动条刻度标签左侧外边距
36
- $spacing-slider_vertical_marks-reverse-marginLeft: -26px;// 垂直滑动条刻度标签左侧外边距(标签在左侧时)
37
+ $spacing-slider_vertical_marks-reverse-marginLeft: -26px; // 垂直滑动条刻度标签左侧外边距(标签在左侧时)
37
38
  $spacing-slider_vertical_rail-top: 0; // 垂直滑动条轨道顶部距离
38
39
  $spacing-slider_vertical_handle-marginTop: 0; // 垂直滑动条原型按钮顶部外边距
39
40
  $spacing-slider_vertical_handle-marginLeft: -10px; // 垂直滑动条原型按钮左侧外边距
@@ -42,7 +43,6 @@ $spacing-slider_vertical_handle-marginLeft: -10px; // 垂直滑动条原型按
42
43
  $radius-slider_rail: var(--semi-border-radius-small); // 滚动条未填充轨道圆角
43
44
  $radius-slider_track: var(--semi-border-radius-small); // 滚动条已填充轨道圆角
44
45
 
45
-
46
46
  // Width/Height
47
47
  $height-slider_wrapper: 32px; // 滚动条容器整体高度
48
48
  $height-slider_vertical_wrapper: 4px; // 垂直滚动条整体宽度
@@ -52,7 +52,7 @@ $width-slider_handle_clicked: 1px; // 滚动条圆形按钮按下后描边宽度
52
52
  $height-slider_track: 4px; // 滚动条已填充轨道高度
53
53
  $width-slider_dot: 4px; // 滚动条圆形刻度点宽度
54
54
  $width-slider_handle_border_disabled: 1px; // 禁用滚动条圆形按钮按下后描边宽度
55
-
55
+ $width-slider_handle-focus: 2px; // 圆形按钮轮廓 - 聚焦
56
56
 
57
57
  // Font
58
58
  $font-slider_rail-fontSize: 14px; // 滚动条轨道文本字号
@@ -103,8 +103,8 @@ $module: #{$prefix}-switch;
103
103
  &-native-control {
104
104
 
105
105
  &[type="checkbox"] {
106
- width: 100%;
107
- height: 100%;
106
+ width: inherit;
107
+ height: inherit;
108
108
  }
109
109
  width: 100%;
110
110
  height: 100%;
@@ -250,7 +250,7 @@ class TimePickerFoundation<P = Record<string, any>, S = Record<string, any>> ext
250
250
  this._adapter.notifyOpenChange(true);
251
251
  }
252
252
 
253
- hanldePanelClose(clickedOutside: boolean, e: any) {
253
+ handlePanelClose(clickedOutside: boolean, e: any) {
254
254
  if (!this._isControlledComponent('open')) {
255
255
  this._adapter.unregisterClickOutSide();
256
256
  this.setPanel(false);
@@ -19,7 +19,7 @@ $spacing-tooltip_content-paddingBottom: $spacing-tight; // 工具提示内容底
19
19
 
20
20
  $font-tooltip-fontSize: $font-size-regular; // 工具提示文本字号
21
21
  $width-tooltip: 240px; // 工具提示宽度 - 默认
22
- $width-tooltip_arrow: 24px; // 工具提示小三角箭头宽度 - 水平
22
+ $width-tooltip_arrow: 24px; // 工具提示小三角箭头宽度 - 水平 ignore-semi-css-trans
23
23
  $height-tooltip_arrow: 7px; // 工具提示小三角箭头高度 - 水平
24
24
 
25
25
  $height-tooltip_arrow_vertical: 24px; // 工具提示小三角箭头高度 - 垂直
@@ -239,6 +239,7 @@ $module: #{$prefix}-tree-select;
239
239
  // right: 0;
240
240
  display: inline-flex;
241
241
  align-items: center;
242
+ flex-shrink: 0;
242
243
  height: 100%;
243
244
  justify-content: center;
244
245
  width: $width-treeSelect_arrow;
@@ -265,6 +266,7 @@ $module: #{$prefix}-tree-select;
265
266
  display: inline-flex;
266
267
  align-items: center;
267
268
  height: 100%;
269
+ flex-shrink: 0;
268
270
  justify-content: center;
269
271
  width: $width-treeSelect_arrow;
270
272
  color: $color-treeSelect_default-icon-default;
package/utils/a11y.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { get } from "lodash";
2
2
 
3
- export function handlePrevent(event: any) {
3
+ export function handlePrevent(event: any) {
4
4
  event.stopPropagation();
5
5
  event.preventDefault();
6
6
  }
@@ -47,7 +47,7 @@ export function setFocusToPreviousMenuItem (itemNodes: HTMLElement[], currentIte
47
47
  }
48
48
 
49
49
  // set focus to the next item in item list
50
- export function setFocusToNextMenuitem (itemNodes: HTMLElement[], currentItem: HTMLElement): void {
50
+ export function setFocusToNextMenuitem (itemNodes: HTMLElement[], currentItem: HTMLElement): void {
51
51
  let newMenuItem: HTMLElement, index: number;
52
52
 
53
53
  if (itemNodes.length > 0){