캐스케이더
캐스케이더 (Cascader)
여러 단계로 이어지는 계층 옵션을 드롭다운 형태로 보여 주는 컴포넌트예요. 주소처럼 단계를 따라 내려가며 선택해야 하는 값을 고를 때 써요.
출처: 문서
본문
API
Cascader
| 속성 | 설명 | 타입 | 기본값 | 버전 |
|---|---|---|---|---|
| allowClear | 선택한 옵션을 비울 수 있는지 여부 | boolean | - |
- |
| animation | 내부 label이 바뀔 때 애니메이션을 넣을지 여부 | boolean | true |
2.15.0 |
| bordered | 테두리를 그릴지 여부 | boolean | true |
- |
| changeOnSelect | true로 두면 선택할 때마다 value가 바뀌어요. mode=multiple일 때는 자식 노드와 부모 노드가 서로 영향을 주지 않아요. |
boolean | - |
- |
| defaultActiveFirstOption | 검색 결과의 첫 번째 옵션을 기본으로 하이라이트할지 여부 | boolean | true |
2.37.0 |
| defaultPopupVisible | 팝업이 기본으로 보이는지 여부 | boolean | - |
- |
| disabled | 비활성 여부 | boolean | - |
- |
| dragToSort | 태그를 드래그로 정렬할 수 있는지 여부 | boolean | - |
2.27.0 |
| error | textarea가 오류 상태인지 여부. (지원 중단 예정, 다음 메이저 버전에서 제거돼요. 대신 status='error'를 쓰세요) | boolean | - |
- |
| loading | 로딩 중인지 여부 | boolean | - |
- |
| popupVisible | 팝업이 보이는지 여부 | boolean | - |
- |
| showEmptyChildren | 선택한 옵션의 children이 빈 배열일 때 다음 단계 노드를 그릴지 여부 | boolean | - |
- |
| unmountOnExit | 숨길 때 팝업을 파괴할지 여부. | boolean | - |
- |
| inputValue | 입력 값 | string | - |
2.34.0 |
| placeholder | 요소의 플레이스홀더 | string | - |
- |
| autoWidth | 너비 자동. minWidth 기본값은 0, maxWidth 기본값은 100% | | boolean| { minWidth?: CSSProperties['minWidth']; maxWidth?: CSSProperties['maxWidth'] } | - |
2.54.0 |
| checkedStrategy | 반환 값을 직접 정해요 parent: 자식 노드가 모두 선택되었을 때 부모 노드만 반환 child: 자식 노드를 반환 |
'parent' | 'child' | child |
2.31.0 |
| expandTrigger | 다음 단계 메뉴를 여는 방식. hover와 click 중 하나 | 'click' | 'hover' | click |
- |
| maxTagCount | tags의 최대 표시 개수. multiple과 label 모드에서만 유효해요. 옵션이 많을 때 responsive 반응형 태그 개수를 설정하는 것은 성능 문제가 생길 수 있어서 권하지 않아요. |
| number| 'responsive'| {count: number | 'responsive';render?: (invisibleTagCount: number) => ReactNode;showPopover?: boolean | Partial<PopoverProps>;} | - |
Object type in 2.37.0. responsive in 2.62.0 |
| mode | 모드를 설정해요 | 'multiple' | - |
- |
| showSearch | 단일 모드 Select가 검색 가능한지 여부. { retainInputValue: true }는 검색창에 포커스가 있을 때 기존 내용을 유지하고,{ retainInputValueWhileSelect: true }는 다중 선택 시 기존 내용을 유지해요.{ panelMode: 'select' }는 옵션을 검색 패널 형태로 보여 줘요 (2.39.0)renderOption은 검색 옵션을 커스텀 렌더링해요 (2.39.0) |
| boolean| {panelMode?: 'cascader' | 'select';renderOption?: (inputValue: string,option: NodeProps<T>,options: extraOptions) => ReactNode;retainInputValue?: boolean;retainInputValueWhileSelect?: boolean;} | - |
- |
| size | 요소의 높이, 24px 28px 32px 36px |
'mini' | 'small' | 'default' | 'large' | - |
- |
| status | 상태 | 'error' | 'warning' | - |
2.45.0 |
| virtualListProps | virtual list props. 가상 스크롤을 켜면 계단식 메뉴의 각 열에 기본 너비가 잡히는데, dropdownMenuColumnStyle로 조절할 수 있어요 |
Pick<VirtualListProps<any>, 'threshold' | 'isStaticItemHeight'> | - |
2.35.0 |
| addBefore | select 필드 앞(왼쪽)에 표시되는 라벨 텍스트 | ReactNode | - |
2.41.0 |
| clearIcon | allowClear일 때 지우기 버튼의 아이콘을 설정해요. |
ReactNode | - |
2.26.0 |
| notFoundContent | 결과가 없을 때 보여 줄 콘텐츠 | ReactNode | - |
- |
| prefix | select 접두사를 커스텀해요 | ReactNode | - |
2.11.0 |
| suffixIcon | select 접미사 아이콘을 커스텀해요 | ReactNode | - |
- |
| arrowIcon | select 화살표 아이콘을 커스텀해요. | ReactNode | null | - |
- |
| className | 추가 css 클래스 | string | string[] | - |
- |
| defaultValue | 초기 값 | (string | string[])[] | - |
- |
| dropdownMenuClassName | 드롭다운 리스트 클래스명을 커스텀해요 | string | string[] | - |
2.35.0 |
| dropdownMenuColumnStyle | 드롭다운 메뉴 열 스타일 | CSSProperties | - |
2.35.0 |
| fieldNames | label, value, isLeaf, disabled, children의 필드 이름을 커스텀해요 | FieldNamesType | DefaultFieldNames |
- |
| filterOption | 검색 로직을 커스텀해요. | (inputValue: string, option: NodeProps<T>) => boolean | - |
- |
| icons | 아이콘 설정. | {loading?: ReactNode;checked?: ReactNode;next?: ReactNode;} | - |
2.50.0 |
| loadMore | 옵션을 지연 로딩해요 | (pathValue: string[], level: number) => Promise<T[]> | - |
- |
| options | 옵션 데이터 | T[] | [] |
- |
| removeIcon | multiple과 label 모드에서 선택된 태그의 삭제 아이콘을 커스텀해요. |
ReactNode | null | - |
- |
| renderFooter | 각 단계 메뉴의 footer를 커스텀 렌더링해요. |
(level: number, activeOption: NodeProps<T> | null) => ReactNode | - |
- |
| renderOption | option을 커스텀 렌더링해요 |
(option: NodeProps<T>, level: number) => ReactNode | - |
- |
| style | 추가 스타일 | CSSProperties | - |
- |
| triggerProps | Trigger 컴포넌트의 모든 props |
Partial<TriggerProps> | - |
- |
| value | 값을 설정해요 | (string | string[])[] | - |
- |
| dropdownColumnRender | 메뉴의 열을 커스텀해요. | (menu: ReactNode, level: number) => ReactNode | - |
2.15.0, level in 2.17.0 |
| dropdownRender | 팝업 메뉴를 커스텀해요. | (menu: ReactNode) => ReactNode | - |
2.15.0 |
| getPopupContainer | selector가 렌더링될 부모 노드. | (node: HTMLElement) => Element | - |
- |
| onChange | 선택을 마쳤을 때의 콜백. | (value: (string | string[])[],selectedOptions,extra: { dropdownVisible?: boolean }) => void | - |
- |
| onClear | 지우기 아이콘을 클릭했을 때의 콜백. | (visible: boolean) => void | - |
- |
| onClick | 마우스가 드롭다운 박스를 클릭했을 때의 콜백 | (e) => void | - |
- |
| onInputValueChange | inputValue가 바뀔 때의 콜백. | (inputValue: string, reason: InputValueChangeReason) => void | - |
2.34.0 |
| onKeyDown | 키보드를 눌렀을 때의 콜백 | (e) => void | - |
2.40.0 |
| onSearch | 입력이 바뀔 때의 콜백. (reason은 2.34.0) |
(inputValue: string, reason: InputValueChangeReason) => void | - |
2.20.0 |
| onVisibleChange | 팝업이 보이거나 숨겨질 때의 콜백. | (visible: boolean) => void | - |
- |
| renderFormat | 반환 값이 입력 박스에 표시돼요. | (valueShow: any[], options?: OptionProps[]) => ReactNode | - |
- |
| renderTag | 태그 렌더링을 커스텀해요. props는 현재 태그 속성, index는 현재 태그의 순번, values는 모든 태그의 값이에요 |
(props: {value: any;label: ReactNode;closable: boolean;onClose: (event) => void;},index: number,values: ObjectValueType[]) => ReactNode | - |
index、values added in 2.15.0 |
extraOptions
export interface extraOptions {
checked: boolean;
}
FieldNamesType
/**
* fieldnames 属性类型
*/
export type FieldNamesType = {
/* Custom field name for label */
label?: string;
/** Custom field name for value */
value?: string;
/** Custom field name for children */
children?: string;
/** Custom field name for disabled */
disabled?: string;
/** Custom field name for isLeaf */
isLeaf?: string;
};
OptionProps
export interface OptionProps {
/**
* @zh 选项的值
* @en: the value of Option
*
*/
value?: string;
/**
* @zh 选项文本
* @en option text
*/
label?: string;
/**
* @zh 是否禁用该选项
* @en whether to disabled
*/
disabled?: boolean;
/**
* @zh 下一级选项
* @en next level menu
*/
children?: OptionProps[];
/**
* @zh 是否是叶子节点
* @en Flag whether it is a leaf node
*/
isLeaf?: boolean;
/**
* @zh 是否禁用复选框选中
* @en Whether to disable the check box is selected
* @version 2.21.0
*/
disableCheckbox?: boolean;
/**
* @zh 其他字段
* @en other fields
*/
[key: string]: any;
}
InputValueChangeReason
// 造成输入框值改变的原因:用户输入、选项下拉框收起、其他
export type InputValueChangeReason =
| "manual"
| "optionListHide"
| "optionChecked";
ObjectValueType
export type ObjectValueType = {
value?: any;
label?: ReactNode;
closable?: boolean;
};
Methods
| 이름 | 설명 | 타입 | 기본값 |
|---|---|---|---|
| focus | 포커스 얻기 | Function |
- |
| blur | 포커스 제거 | Function |
- |
Demo
<Cascader ref={(ref) => (this.select = ref)} />;
this.select.focus();
this.select.blur();
더 알아보기 (Learn more)
Cascader 컴포넌트의 최신 API와 예시는 Arco Design 공식 문서에서 확인할 수 있어요.