forked from cerc-io/snowballtools-base
fix(ProjectSearchBarDialog): getMenuProps
error (#221)
- Replaced `useDebounce` with `useDebounceValue` for better type inference and simplicity - Added `getMenuProps` to `useCombobox` to support better accessibility and usability - Minor style tweak to improve `ProjectSearch` header hover effect - Created Storybook stories for the `ProjectSearchBar` component ---
This commit is contained in:
parent
dee84f18cb
commit
f981f1a3f6
@ -1,7 +1,7 @@
|
||||
import { useCallback, useEffect, useState } from 'react';
|
||||
import { useCombobox } from 'downshift';
|
||||
import { Project } from 'gql-client';
|
||||
import { useDebounce } from 'usehooks-ts';
|
||||
import { useDebounceValue } from 'usehooks-ts';
|
||||
|
||||
import SearchBar from 'components/SearchBar';
|
||||
import { useGQLClient } from 'context/GQLClientContext';
|
||||
@ -42,7 +42,7 @@ export const ProjectSearchBar = ({ onChange }: ProjectSearchBarProps) => {
|
||||
},
|
||||
});
|
||||
|
||||
const debouncedInputValue = useDebounce<string>(inputValue, 300);
|
||||
const [debouncedInputValue, _] = useDebounceValue<string>(inputValue, 300);
|
||||
|
||||
const fetchProjects = useCallback(
|
||||
async (inputValue: string) => {
|
||||
|
@ -5,7 +5,7 @@ import { CrossIcon, SearchIcon } from 'components/shared/CustomIcon';
|
||||
import { Input } from 'components/shared/Input';
|
||||
import { useGQLClient } from 'context/GQLClientContext';
|
||||
import { Project } from 'gql-client';
|
||||
import { useDebounce } from 'usehooks-ts';
|
||||
import { useDebounceValue } from 'usehooks-ts';
|
||||
import { ProjectSearchBarItem } from './ProjectSearchBarItem';
|
||||
import { ProjectSearchBarEmpty } from './ProjectSearchBarEmpty';
|
||||
import { useNavigate } from 'react-router-dom';
|
||||
@ -27,8 +27,13 @@ export const ProjectSearchBarDialog = ({
|
||||
const client = useGQLClient();
|
||||
const navigate = useNavigate();
|
||||
|
||||
const { getInputProps, getItemProps, inputValue, setInputValue } =
|
||||
useCombobox({
|
||||
const {
|
||||
getInputProps,
|
||||
getItemProps,
|
||||
getMenuProps,
|
||||
inputValue,
|
||||
setInputValue,
|
||||
} = useCombobox({
|
||||
items,
|
||||
itemToString(item) {
|
||||
return item ? item.name : '';
|
||||
@ -45,7 +50,7 @@ export const ProjectSearchBarDialog = ({
|
||||
},
|
||||
});
|
||||
|
||||
const debouncedInputValue = useDebounce<string>(inputValue, 300);
|
||||
const [debouncedInputValue, _] = useDebounceValue<string>(inputValue, 300);
|
||||
|
||||
const fetchProjects = useCallback(
|
||||
async (inputValue: string) => {
|
||||
@ -86,7 +91,7 @@ export const ProjectSearchBarDialog = ({
|
||||
</Button>
|
||||
</div>
|
||||
{/* Content */}
|
||||
<div className="flex flex-col gap-1 px-2 py-2">
|
||||
<div className="flex flex-col gap-1 px-2 py-2" {...getMenuProps()}>
|
||||
{items.length > 0
|
||||
? items.map((item, index) => (
|
||||
<>
|
||||
|
@ -32,7 +32,7 @@ const ProjectSearch = () => {
|
||||
return (
|
||||
<section className="h-full flex flex-col">
|
||||
{/* Header */}
|
||||
<div className="sticky hidden lg:block top-0 border-b bg-base-bg border-border-separator/[0.06] z-30">
|
||||
<div className="sticky hidden lg:block top-0 border-b bg-base-bg border-border-separator/[0.06] hover:z-30">
|
||||
<div className="flex pr-6 pl-2 py-2 items-center">
|
||||
<div className="flex-1">
|
||||
<ProjectSearchBar
|
||||
|
@ -0,0 +1,20 @@
|
||||
import { StoryObj, Meta } from '@storybook/react';
|
||||
|
||||
import { ProjectSearchBar } from 'components/projects/ProjectSearchBar';
|
||||
|
||||
const meta: Meta<typeof ProjectSearchBar> = {
|
||||
title: 'Components/ProjectSearchBar',
|
||||
component: ProjectSearchBar,
|
||||
tags: ['autodocs'],
|
||||
argTypes: {
|
||||
onChange: {
|
||||
action: 'change',
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
export default meta;
|
||||
|
||||
type Story = StoryObj<typeof ProjectSearchBar>;
|
||||
|
||||
export const Default: Story = {};
|
Loading…
Reference in New Issue
Block a user