@gm-pc/react 1.28.0-y.0 → 1.28.1-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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gm-pc/react",
3
- "version": "1.28.0-y.0",
3
+ "version": "1.28.1-beta.0",
4
4
  "description": "观麦前端基础组件库",
5
5
  "author": "liyatang <liyatang@qq.com>",
6
6
  "homepage": "https://github.com/gmfe/gm-pc#readme",
@@ -24,7 +24,7 @@
24
24
  "dependencies": {
25
25
  "@gm-common/hooks": "^2.10.0",
26
26
  "@gm-common/tool": "^2.10.0",
27
- "@gm-pc/locales": "^1.28.0-y.0",
27
+ "@gm-pc/locales": "^1.28.1-beta.0",
28
28
  "big.js": "^6.0.1",
29
29
  "classnames": "^2.2.5",
30
30
  "lodash": "^4.17.19",
@@ -48,5 +48,5 @@
48
48
  "react-router-dom": "^5.2.0",
49
49
  "react-window": "^1.8.5"
50
50
  },
51
- "gitHead": "553a50edcf56e3bc001e96d2e6f752344b51021d"
51
+ "gitHead": "21e6355e34d987a7243fbdb16d3d3c4981a59344"
52
52
  }
@@ -23,6 +23,7 @@ import { ConfigConsumer, ConfigProvider, ConfigProviderProps } from '../config_p
23
23
  import { Checkbox } from '../checkbox'
24
24
  import { Switch } from '../switch'
25
25
  interface MoreSelectBaseState {
26
+ canClear?: boolean
26
27
  searchValue: string
27
28
  loading: boolean
28
29
  /* keyboard 默认第一个位置 */
@@ -212,6 +213,12 @@ class MoreSelectBase<V extends string | number = string> extends Component<
212
213
  onSelect(willSelected)
213
214
  }
214
215
 
216
+ private _handleClearAll = (event: MouseEvent): void => {
217
+ event.stopPropagation()
218
+ const { onSelect = _.noop } = this.props
219
+ onSelect([])
220
+ }
221
+
215
222
  private _handlePopupKeyDown = (event: KeyboardEvent<HTMLDivElement>): void => {
216
223
  const { onKeyDown } = this.props
217
224
  let willActiveIndex = this.state.willActiveIndex as number
@@ -402,36 +409,38 @@ class MoreSelectBase<V extends string | number = string> extends Component<
402
409
  listHeight,
403
410
  } = this.props
404
411
 
405
- const selectedValues = new Set(selected.map((v) => v.value))
412
+ const selectedValues = new Set(selected?.map((v) => v.value))
406
413
 
407
414
  // 分离已勾选和未勾选的数据
408
415
  const availableGroups: MoreSelectGroupDataItem<V>[] = []
416
+ // 已选中区域直接使用 selected 构建,不受筛选影响
417
+ const selectedGroups: MoreSelectGroupDataItem<V>[] = []
409
418
 
410
- filterData.forEach((group) => {
411
- const availableChildren = group.children.filter(
412
- (item) => !selectedValues.has(item.value)
413
- )
419
+ if (multiple) {
420
+ filterData.forEach((group) => {
421
+ const availableChildren = group.children.filter(
422
+ (item) => !selectedValues.has(item.value)
423
+ )
424
+
425
+ if (availableChildren.length > 0) {
426
+ availableGroups.push({
427
+ ...group,
428
+ children: availableChildren,
429
+ })
430
+ }
431
+ })
414
432
 
415
- if (availableChildren.length > 0) {
416
- availableGroups.push({
417
- ...group,
418
- children: availableChildren,
433
+ if (selected.length > 0) {
434
+ selectedGroups.push({
435
+ label: '',
436
+ children: selected,
419
437
  })
420
438
  }
421
- })
422
-
423
- // 已选中区域直接使用 selected 构建,不受筛选影响
424
- const selectedGroups: MoreSelectGroupDataItem<V>[] = []
425
- if (selected.length > 0) {
426
- selectedGroups.push({
427
- label: '',
428
- children: selected,
429
- })
430
439
  }
431
440
 
432
441
  return (
433
442
  <div style={{ height: listHeight, overflow: 'auto' }}>
434
- {selectedGroups.length > 0 && (
443
+ {selected.length > 0 && multiple && (
435
444
  <>
436
445
  <div className='gm-more-select-section-title gm-padding-5 gm-text-desc gm-text-12'>
437
446
  已选中
@@ -445,28 +454,28 @@ class MoreSelectBase<V extends string | number = string> extends Component<
445
454
  renderItem={renderListItem}
446
455
  onSelect={this._handleSelect}
447
456
  isScrollTo={false}
448
- willActiveIndex={willActiveIndex!}
449
457
  />
450
458
  </>
451
459
  )}
452
- {availableGroups.length > 0 && (
453
- <>
460
+ <>
461
+ {multiple && (
454
462
  <div className='gm-more-select-section-title gm-padding-5 gm-text-desc gm-text-12'>
455
463
  未选中
456
464
  </div>
457
- <ListBase
458
- selected={selected.map((v) => v.value)}
459
- data={availableGroups}
460
- multiple={multiple}
461
- isGroupList={isGroupList}
462
- className='gm-border-0'
463
- renderItem={renderListItem}
464
- onSelect={this._handleSelect}
465
- isScrollTo={false}
466
- willActiveIndex={willActiveIndex!}
467
- />
468
- </>
469
- )}
465
+ )}
466
+
467
+ <ListBase
468
+ selected={selected?.map((v) => v.value)}
469
+ data={multiple ? availableGroups : filterData}
470
+ multiple={multiple}
471
+ isGroupList={isGroupList}
472
+ className='gm-border-0'
473
+ renderItem={renderListItem}
474
+ onSelect={this._handleSelect}
475
+ isScrollTo
476
+ willActiveIndex={willActiveIndex!}
477
+ />
478
+ </>
470
479
  </div>
471
480
  )
472
481
  }
@@ -635,6 +644,10 @@ class MoreSelectBase<V extends string | number = string> extends Component<
635
644
  )}
636
645
  </Flex>
637
646
  )}
647
+ <SVGRemove
648
+ className='gm-cursor gm-more-select-clear-btn'
649
+ onClick={disabled ? _.noop : this._handleClearAll}
650
+ />
638
651
  </>
639
652
  )
640
653
  }