Skip to content

Commit

Permalink
fix(cascader): add itemPosition attr (#1689)
Browse files Browse the repository at this point in the history
  • Loading branch information
berber1016 committed Dec 15, 2021
1 parent 2ca9bb0 commit b554264
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 4 deletions.
2 changes: 2 additions & 0 deletions src/cascader/Cascader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export const Cascader: React.FC<CascaderProps> = ({
placement = 'bottomLeft',
children,
strategy = 'fixed',
itemStrategy = 'fixed',
onClear,
allowClear,
title: controlledTitle,
Expand Down Expand Up @@ -117,6 +118,7 @@ export const Cascader: React.FC<CascaderProps> = ({
suffix={suffix}
style={contentStyle}
model="cascader"
itemStrategy={itemStrategy}
>
{children}
</List>
Expand Down
1 change: 1 addition & 0 deletions src/cascader/interfance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export interface CascaderProps extends Omit<ListProps, 'options' | 'onChange' |
contentStyle?: React.CSSProperties;
placement?: Placement;
strategy?: 'fixed' | 'absolute';
itemStrategy?: 'fixed' | 'absolute';
/** ================ trigger 相关的属性 ============== */
/**
* trigger className
Expand Down
3 changes: 2 additions & 1 deletion src/list/Item.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import WithRef from '../utils/withRef';
import { ListContext } from './context';

export const InnerItem = WithRef<HTMLLIElement, ItemProps>((props, ref?) => {
const { label, value, disabled, ...rest } = props;
const { label, value, disabled, strategy, ...rest } = props;
const { model } = useContext(ListContext);
if (model === 'multiple') {
return (
Expand All @@ -29,6 +29,7 @@ export const InnerItem = WithRef<HTMLLIElement, ItemProps>((props, ref?) => {
label={label as string}
value={value as string}
disabled={disabled}
strategy={strategy}
{...rest}
/>
);
Expand Down
3 changes: 2 additions & 1 deletion src/list/List.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ export const InnerList = WithRef<HTMLDivElement, ListProps>((props, ref?) => {
onChange: controlledOnChange,
renderItem,
onClick,
itemStrategy,
...listRestProps
} = props;

Expand Down Expand Up @@ -112,7 +113,7 @@ export const InnerList = WithRef<HTMLDivElement, ListProps>((props, ref?) => {
const renderChildren = (option: OptionProps) => {
const renderedItem = renderItem?.(option);
return (
<Item {...option} key={option.value}>
<Item {...option} strategy={itemStrategy} key={option.value}>
{renderedItem}
</Item>
);
Expand Down
4 changes: 2 additions & 2 deletions src/list/inner/CascaderItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const CascaderItem: React.ForwardRefRenderFunction<
HTMLLIElement,
CascaderItemProps & Omit<DOMAttributes<HTMLLIElement>, 'onClick'>
> & { isItem?: boolean } = (
{ label, value, children, childrens = [], disabled, onClick: propsOnClick, ...rest },
{ label, value, children, childrens = [], disabled, onClick: propsOnClick, strategy = 'fixed', ...rest },
ref?
) => {
const prefixCls = usePrefixCls('cascader');
Expand Down Expand Up @@ -85,7 +85,7 @@ const CascaderItem: React.ForwardRefRenderFunction<
// document click contains node
getContainer={(node) => node || document.body}
content={content()}
strategy="fixed"
strategy={strategy}
distoryOnHide={false}
offset={[0, 12]}
>
Expand Down
3 changes: 3 additions & 0 deletions src/list/interfance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ export interface ListProps {
* 仅支持options 形式。自定义 item render 自定义render时会劫持onClick方法提供给List来使用
*/
renderItem?: (option: OptionProps) => React.ReactElement;
itemStrategy?: 'fixed' | 'absolute';
}

export interface DragListProps extends Omit<ListProps, 'model' | 'onChange' | 'value' | 'children'> {
Expand Down Expand Up @@ -98,6 +99,7 @@ export interface DragItemProps extends ItemProps {
export interface CascaderItemProps extends BaseItemProps {
label: string;
value: string | number;
strategy?: 'fixed' | 'absolute';
childrens?: CascaderItemProps[];
}
export interface ItemProps
Expand All @@ -118,6 +120,7 @@ export interface ItemProps
| 'wrapper'
> {
selectValue?: string | string[];
strategy?: 'fixed' | 'absolute';
}

export interface BaseItemProps extends Pick<OptionProps, 'value' | 'disabled' | 'prefix' | 'suffix' | 'wrapper'> {
Expand Down

1 comment on commit b554264

@vercel
Copy link

@vercel vercel bot commented on b554264 Dec 15, 2021

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.