Even better dropdown filtering

This commit is contained in:
Gregory Schier
2024-02-17 22:27:01 -08:00
parent 8ff2caf3c3
commit b57ea8adeb
3 changed files with 25 additions and 33 deletions
@@ -132,7 +132,6 @@ export function GrpcConnectionSetupPane({
const tabs: TabItem[] = useMemo( const tabs: TabItem[] = useMemo(
() => [ () => [
{ value: 'message', label: 'Message' }, { value: 'message', label: 'Message' },
{ value: 'metadata', label: 'Metadata' },
{ {
value: 'auth', value: 'auth',
label: 'Auth', label: 'Auth',
@@ -149,6 +148,7 @@ export function GrpcConnectionSetupPane({
}, },
}, },
}, },
{ value: 'metadata', label: 'Metadata' },
], ],
[], [],
); );
+5 -14
View File
@@ -236,7 +236,7 @@ const Menu = forwardRef<Omit<DropdownRef, 'open' | 'isOpen' | 'toggle'>, MenuPro
const isSpecial = e.ctrlKey || e.metaKey || e.altKey; const isSpecial = e.ctrlKey || e.metaKey || e.altKey;
if (isCharacter && !isSpecial) { if (isCharacter && !isSpecial) {
e.preventDefault(); e.preventDefault();
setFilter((f) => f + e.key); setFilter((f) => (f + e.key).trim());
setSelectedIndex(0); setSelectedIndex(0);
} else if (e.key === 'Backspace' && !isSpecial) { } else if (e.key === 'Backspace' && !isSpecial) {
e.preventDefault(); e.preventDefault();
@@ -356,10 +356,7 @@ const Menu = forwardRef<Omit<DropdownRef, 'open' | 'isOpen' | 'toggle'>, MenuPro
}, [triggerShape, containerWidth]); }, [triggerShape, containerWidth]);
const filteredItems = useMemo( const filteredItems = useMemo(
() => () => items.filter((i) => getNodeText(i.label).toLowerCase().includes(filter.toLowerCase())),
items.filter(
(i) => filter === '' || getNodeText(i.label).toLowerCase().includes(filter.toLowerCase()),
),
[items, filter], [items, filter],
); );
@@ -425,22 +422,16 @@ const Menu = forwardRef<Omit<DropdownRef, 'open' | 'isOpen' | 'toggle'>, MenuPro
<HStack <HStack
space={2} space={2}
alignItems="center" alignItems="center"
className="py-0.5 px-1.5 mb-1 text-xs border border-highlight mx-2 rounded font-mono" className="pb-0.5 px-1.5 mb-2 text-xs border border-highlight mx-2 rounded font-mono h-2xs"
> >
<Icon icon="search" size="xs" className="text-gray-600" /> <Icon icon="search" size="xs" className="text-gray-700" />
<div className="text-gray-800">{filter}</div> <div className="text-gray-800">{filter}</div>
</HStack> </HStack>
)} )}
{filteredItems.length === 0 && ( {filteredItems.length === 0 && (
<span className="text-gray-500 text-sm text-center px-2 py-1">No matches</span> <span className="text-gray-500 text-sm text-center px-2 py-1">No matches</span>
)} )}
{items {filteredItems.map((item, i) => {
.filter(
(i) =>
filter === '' ||
getNodeText(i.label).toLowerCase().includes(filter.toLowerCase()),
)
.map((item, i) => {
if (item.type === 'separator') { if (item.type === 'separator') {
return ( return (
<Separator key={i} className={classNames('my-1.5', item.label && 'ml-2')}> <Separator key={i} className={classNames('my-1.5', item.label && 'ml-2')}>
+1
View File
@@ -1,6 +1,7 @@
const plugin = require('tailwindcss/plugin'); const plugin = require('tailwindcss/plugin');
const height = { const height = {
'2xs': '1.5rem',
xs: '1.75rem', xs: '1.75rem',
sm: '2.0rem', sm: '2.0rem',
md: '2.5rem', md: '2.5rem',