Fix multi-select menus and selected label rendering
This commit is contained in:
1 parent
0941ea06f9
commit
cfe8020831
10 files changed
+142
-38
No files matched your search
@@ -11,7 +11,7 @@ import {
|
||||
} from '@umami/react-zen';
|
||||
import { useState } from 'react';
|
||||
import { Empty } from '@/components/common/Empty';
|
||||
import { MultiSelect } from '@/components/common/MultiSelect';
|
||||
import { MultiSelect, MultiSelectItem } from '@/components/common/MultiSelect';
|
||||
import { useFilters, useFormat, useWebsiteValuesQuery } from '@/components/hooks';
|
||||
import { X } from '@/components/icons';
|
||||
import { isSearchOperator } from '@/lib/params';
|
||||
@@ -108,9 +108,9 @@ export function FilterRecord({
|
||||
allowSearch
|
||||
>
|
||||
{items.map(({ value }) => (
|
||||
<ListItem key={value} id={value}>
|
||||
<MultiSelectItem key={value} value={value}>
|
||||
{formatValue(value, type)}
|
||||
</ListItem>
|
||||
</MultiSelectItem>
|
||||
))}
|
||||
</MultiSelect>
|
||||
)}
|
||||
|
||||
@@ -35,5 +35,5 @@ export function LinkButton({
|
||||
</Link>
|
||||
);
|
||||
|
||||
return <Button {...props} variant={variant} render={linkElement} />;
|
||||
return <Button {...props} variant={variant} nativeButton={false} render={linkElement} />;
|
||||
}
|
||||
@@ -1,11 +1,14 @@
|
||||
import { Button, Column, Icon, List, MenuTrigger, Popover, SearchField } from '@umami/react-zen';
|
||||
import type { ReactNode } from 'react';
|
||||
import { Button, Icon, Menu, MenuItem, MenuTrigger, SearchField } from '@umami/react-zen';
|
||||
import { Children, type ReactNode } from 'react';
|
||||
import { ChevronRight } from '@/components/icons';
|
||||
|
||||
const listStyle = {
|
||||
maxHeight: 'min(320px, calc(100dvh - 8rem))',
|
||||
overflowY: 'auto' as const,
|
||||
};
|
||||
|
||||
const menuItemProps = { closeOnClick: false };
|
||||
|
||||
interface MultiSelectProps {
|
||||
value?: string[];
|
||||
onChange?: (values: string[]) => void;
|
||||
@@ -18,6 +21,14 @@ interface MultiSelectProps {
|
||||
children: ReactNode;
|
||||
}
|
||||
|
||||
export function MultiSelectItem({ value, children }: { value: string; children: ReactNode }) {
|
||||
return (
|
||||
<MenuItem id={value} {...menuItemProps}>
|
||||
{children}
|
||||
</MenuItem>
|
||||
);
|
||||
}
|
||||
|
||||
export function MultiSelect({
|
||||
value = [],
|
||||
onChange,
|
||||
@@ -49,28 +60,35 @@ export function MultiSelect({
|
||||
<ChevronRight />
|
||||
</Icon>
|
||||
</Button>
|
||||
<Popover style={{ minWidth: 'var(--trigger-width)', maxWidth: 'var(--trigger-width)' }}>
|
||||
<Column
|
||||
gap="2"
|
||||
padding="2"
|
||||
border
|
||||
borderRadius="md"
|
||||
shadow="lg"
|
||||
className="bg-surface-overlay"
|
||||
>
|
||||
{allowSearch && <SearchField value={searchValue} onSearch={onSearch} autoFocus />}
|
||||
<List
|
||||
selectionMode="multiple"
|
||||
value={value}
|
||||
onChange={onChange}
|
||||
showCheckmark
|
||||
style={listStyle}
|
||||
renderEmptyState={renderEmptyState}
|
||||
>
|
||||
{children}
|
||||
</List>
|
||||
</Column>
|
||||
</Popover>
|
||||
<Menu
|
||||
selectionMode="multiple"
|
||||
selectedKeys={value}
|
||||
onSelectionChange={keys =>
|
||||
onChange?.(keys === 'all' ? [] : Array.from(keys, key => String(key)))
|
||||
}
|
||||
className="flex flex-col gap-2"
|
||||
style={{
|
||||
width: 'var(--anchor-width)',
|
||||
maxWidth: 'var(--available-width)',
|
||||
}}
|
||||
>
|
||||
{allowSearch && (
|
||||
<SearchField
|
||||
value={searchValue}
|
||||
onSearch={onSearch}
|
||||
autoFocus
|
||||
onKeyDown={event => {
|
||||
if (event.key !== 'Escape' && event.key !== 'Tab') {
|
||||
event.stopPropagation();
|
||||
}
|
||||
}}
|
||||
/>
|
||||
)}
|
||||
<div style={listStyle}>
|
||||
{children}
|
||||
{Children.count(children) === 0 && renderEmptyState?.()}
|
||||
</div>
|
||||
</Menu>
|
||||
</MenuTrigger>
|
||||
);
|
||||
}
|
||||
@@ -48,7 +48,14 @@ export function MetricsExpandedTable({
|
||||
return (
|
||||
<>
|
||||
<Row alignItems="center" paddingBottom="3">
|
||||
{allowSearch && <SearchField value={search} onSearch={setSearch} delay={300} />}
|
||||
{allowSearch && (
|
||||
<SearchField
|
||||
value={search}
|
||||
onSearch={setSearch}
|
||||
delay={300}
|
||||
className="w-full max-w-md"
|
||||
/>
|
||||
)}
|
||||
<Row justifyContent="flex-end" flexGrow={1} gap>
|
||||
{children}
|
||||
{allowDownload && <DownloadButton filename={type} data={data} />}
|
||||
|
||||
@@ -20,7 +20,7 @@ import { useState } from 'react';
|
||||
import { ComboBox } from '@/components/common/ComboBox';
|
||||
import { DateDisplay } from '@/components/common/DateDisplay';
|
||||
import { Empty } from '@/components/common/Empty';
|
||||
import { MultiSelect } from '@/components/common/MultiSelect';
|
||||
import { MultiSelect, MultiSelectItem } from '@/components/common/MultiSelect';
|
||||
import { useMessages, usePropertyValuesQuery } from '@/components/hooks';
|
||||
import type { PropertyDataSource } from '@/components/hooks/queries/usePropertyFieldsQuery';
|
||||
import { X } from '@/components/icons';
|
||||
@@ -222,9 +222,9 @@ export function PropertyFilterRecord({
|
||||
}
|
||||
>
|
||||
{filteredValues.map(v => (
|
||||
<ListItem key={v} id={v}>
|
||||
<MultiSelectItem key={v} value={v}>
|
||||
{v}
|
||||
</ListItem>
|
||||
</MultiSelectItem>
|
||||
))}
|
||||
</MultiSelect>
|
||||
)}
|
||||
|
||||
Reference in new issue
Block a user