diff --git a/src/components/TreeSelect/TreeSelect.scss b/src/components/TreeSelect/TreeSelect.scss index a12d97fa41..ad7cf33af3 100644 --- a/src/components/TreeSelect/TreeSelect.scss +++ b/src/components/TreeSelect/TreeSelect.scss @@ -3,6 +3,12 @@ $block: '.#{variables.$ns}tree-select'; #{$block} { + max-width: 100%; + + &_width_max { + width: 100%; + } + &__popup { overflow: hidden; min-width: 300px; diff --git a/src/components/TreeSelect/TreeSelect.tsx b/src/components/TreeSelect/TreeSelect.tsx index aa7c34bef8..b785583774 100644 --- a/src/components/TreeSelect/TreeSelect.tsx +++ b/src/components/TreeSelect/TreeSelect.tsx @@ -16,7 +16,7 @@ import { useListKeydown, useListState, } from '../useList'; -import {block} from '../utils/cn'; +import {type CnMods, block} from '../utils/cn'; import {TreeListContainer} from './components/TreeListContainer/TreeListContainer'; import {useTreeSelectSelection, useValue} from './hooks/useTreeSelectSelection'; @@ -37,6 +37,8 @@ export const TreeSelect = React.forwardRef(function TreeSelect( size = 'm', items, defaultOpen, + className, + width, popupClassName, open: propsOpen, multiple, @@ -224,8 +226,24 @@ export const TreeSelect = React.forwardRef(function TreeSelect( /> ); + const mods: CnMods = { + ...(width === 'max' && {width}), + }; + + const inlineStyles: React.CSSProperties = {}; + + if (typeof width === 'number') { + inlineStyles.width = width; + } + return ( - + {togglerNode} ( }); // assign components scope logic - state.selectable = context.groupState + state.hasSelectionIcon = context.groupState ? groupsBehavior === 'selectable' : undefined; diff --git a/src/components/TreeSelect/__stories__/TreeSelect.stories.tsx b/src/components/TreeSelect/__stories__/TreeSelect.stories.tsx index 8a48680eb6..ee0de0674e 100644 --- a/src/components/TreeSelect/__stories__/TreeSelect.stories.tsx +++ b/src/components/TreeSelect/__stories__/TreeSelect.stories.tsx @@ -25,7 +25,6 @@ import { WithItemLinksAndActionsExampleProps, } from './components/WithItemLinksAndActionsExample'; -// TODO: пример с кастомной структурой данных export default { title: 'Unstable/TreeSelect', component: TreeSelect, diff --git a/src/components/TreeSelect/__stories__/components/WithFiltrationAndControlsExample.tsx b/src/components/TreeSelect/__stories__/components/WithFiltrationAndControlsExample.tsx index 0cd53c850f..b4f6abda50 100644 --- a/src/components/TreeSelect/__stories__/components/WithFiltrationAndControlsExample.tsx +++ b/src/components/TreeSelect/__stories__/components/WithFiltrationAndControlsExample.tsx @@ -7,7 +7,7 @@ import {Flex, spacing} from '../../../layout'; import {useListFilter} from '../../../useList'; import {createRandomizedData} from '../../../useList/__stories__/utils/makeData'; import {TreeSelect} from '../../TreeSelect'; -import type {TreeSelectProps} from '../../types'; +import type {RenderContainerProps, TreeSelectProps} from '../../types'; import {RenderVirtualizedContainer} from './RenderVirtualizedContainer'; @@ -23,7 +23,23 @@ export const WithFiltrationAndControlsExample = ({ itemsCount = 5, ...props }: WithFiltrationAndControlsExampleProps) => { - const items = React.useMemo(() => createRandomizedData({num: itemsCount}), [itemsCount]); + const {items, renderContainer} = React.useMemo(() => { + const baseItems = createRandomizedData({num: itemsCount}); + const containerRenderer = (props: RenderContainerProps<{title: string}>) => { + if (props.items.length === 0 && baseItems.length > 0) { + return ( + + Nothing found + + ); + } + + return ; + }; + + return {items: baseItems, renderContainer: containerRenderer}; + }, [itemsCount]); + const [open, onOpenChange] = React.useState(true); const [value, setValue] = React.useState([]); const filterState = useListFilter({items}); @@ -48,17 +64,7 @@ export const WithFiltrationAndControlsExample = ({ ref={filterState.filterRef} /> } - renderContainer={(props) => { - if (props.items.length === 0 && items.length > 0) { - return ( - - Nothing found - - ); - } - - return ; - }} + renderContainer={renderContainer} slotAfterListBody={