Skip to content

Commit

Permalink
fix(select): fix select group listHeight (#600)
Browse files Browse the repository at this point in the history
affects: @gio-design/components

Co-authored-by: shiliqian <[email protected]>
  • Loading branch information
berber1016 and shiliqian authored Dec 9, 2020
1 parent bbd4853 commit 70a9b01
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 22 deletions.
26 changes: 13 additions & 13 deletions packages/components/src/components/list/interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@ export interface IBaseListProps {
*/
value?: any;
/**
列表宽度
列表宽度
*/
width?: number | string;
/**
列表高度
列表高度
*/
height?: number;
height?: number | string;
/**
包裹样式
*/
Expand All @@ -44,19 +44,19 @@ export interface IBaseListProps {
*/
labelRenderer?: (option: Option, isGruop: false) => ReactNode;
/**
自定义行高
自定义行高
*/
rowHeight?: number | ((option: Option) => number);
/**
选中的回调
*/
onSelect?: (selectedValue: string, value: ListValueType, option: Option) => void;
/**
取消选中的回调
取消选中的回调
*/
onDeselect?: (selectedValue: string, value: ListValueType, option: Option) => void;
/**
点击触发的回调
点击触发的回调
*/
onClick?: (value: any) => void;
getPopupContainer?: (node: HTMLElement) => HTMLElement;
Expand All @@ -69,27 +69,27 @@ export interface Option {
*/
label: string;
/**
作为列表的 `key` 来使用
作为列表的 `key` 来使用
*/
value: string;
/**
列表次要文字
列表次要文字
*/
description?: string;
/**
是否禁用
是否禁用
*/
disabled?: boolean;
/**
`tooltip` 描述
`tooltip` 描述
*/
tooltip?: string;
/**
分组的 `key` ,与 `groupLabel` 一起使用
*/
groupValue?: string;
/**
分组的标题
分组的标题
*/
groupLabel?: string;
}
Expand All @@ -105,7 +105,7 @@ export interface SelectCoreProps {
stateless?: boolean;
allowDuplicate?: boolean;
max?: number;
height?: number;
height?: number | string;
rowHeight?: number | ((option: any) => number);
isLoading?: boolean;
required?: boolean;
Expand Down Expand Up @@ -136,7 +136,7 @@ export interface SelectListProps {
allowDuplicate?: boolean;
required?: boolean;
max?: number;
height: number;
height: number | string;
rowHeight: number | ((option: any) => number);
onSelect?: (value: any, selectedValue?: any | any[], option?: any) => void;
onDeselect?: (value: any, selectedValue?: any | any[], option?: any) => void;
Expand Down
1 change: 1 addition & 0 deletions packages/components/src/components/list/list.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ class SelectList extends React.Component<SelectListProps & ConfigConsumerProps>
return (
<AutoSizer style={{ width: '100%', height: '100%' }}>
{({ width }) => (

<List
value={value}
width={width}
Expand Down
8 changes: 2 additions & 6 deletions packages/components/src/components/select/Select.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React, { useState, useContext, useMemo, useRef, useEffect, useCallback }
import classnames from 'classnames';

import { DownFilled, CloseCircleFilled } from '@gio-design/icons';
import { filter, isNil, without, uniqueId, uniqBy, findIndex, concat } from 'lodash';
import { filter, isNil, without, uniqueId, findIndex, concat } from 'lodash';
import { SizeContext } from '../config-provider/SizeContext';
import Dropdown from '../dropdown';
import Tag from '../tag';
Expand Down Expand Up @@ -273,10 +273,6 @@ const RenderSelect: React.ForwardRefRenderFunction<unknown, SelectProps> = (prop
: filteredOptions,
[hasExactMatch, allowCustomOption, filteredOptions, input, hasGroup]
);
const groupCount = useMemo(() => (hasGroup ? uniqBy(completeOptions, 'groupValue').length : 0), [
completeOptions,
hasGroup,
]);

const onValueChange = (optValue: MaybeArray<string | number>) => {
if (!isControlled) {
Expand Down Expand Up @@ -442,7 +438,7 @@ const RenderSelect: React.ForwardRefRenderFunction<unknown, SelectProps> = (prop
onDeselect={onListDeselect}
height={
listHeight ||
(completeOptions.length + groupCount) * listRowHeight - groupCount * 10 - (groupCount !== 0 ? 16 : 0)
'100%'
}
rowHeight={listRowHeight}
/>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const labels = ['全部', '已上线', '待上线', '已下线', '草稿'];
const values = ['all', 'online', 'pending', 'off', 'draft'];
const numberValues = [10,20,30,40,50];
const numberValues = [10, 20, 30, 40, 50];

const options = values.map((value, index) => ({
value,
Expand All @@ -20,9 +20,9 @@ const optionsWithoutGroup = values.map((value, index) => ({
}));

const optionsWithChildren = values.map((value, index) => ({
value:`${value}-自定义`,
value: `${value}-自定义`,
label: `${labels[index]}-自定义`,
}));

export { optionsWithoutGroup,optionsWithChildren,numberOptions };
export { optionsWithoutGroup, optionsWithChildren, numberOptions };
export default options;

1 comment on commit 70a9b01

@vercel
Copy link

@vercel vercel bot commented on 70a9b01 Dec 9, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.