Skip to content

Commit

Permalink
feat: make charLimit a parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
agoose77 committed Oct 2, 2024
1 parent 14b8094 commit db27fa1
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions packages/site/src/components/Navigation/Search.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -212,8 +212,10 @@ function SearchShortcut() {
function SearchResultItem({
result,
closeSearch,
charLimit,
}: {
result: RankedSearchResult;
charLimit?: number;
closeSearch?: () => void;
}) {
const { hierarchy, type, url, queries } = result;
Expand All @@ -238,7 +240,7 @@ function SearchResultItem({
<MarkedText
text={title}
matches={matches}
limit={type === 'content' ? 64 : undefined}
limit={type === 'content' ? charLimit : undefined}
className="text-sm"
/>
);
Expand Down Expand Up @@ -280,6 +282,7 @@ interface SearchResultsProps {
searchListID: string;
searchLabelID: string;
selectedIndex: number;
charLimit?: number;
onHoverSelect: (index: number) => void;
className?: string;
closeSearch?: () => void;
Expand All @@ -289,6 +292,7 @@ function SearchResults({
searchResults,
searchListID,
searchLabelID,
charLimit,
className,
selectedIndex,
onHoverSelect,
Expand Down Expand Up @@ -363,7 +367,7 @@ function SearchResults({
// Trigger selection on movement, so that scrolling doesn't trigger handler
onMouseMove={handleMouseMove}
>
<SearchResultItem result={result} closeSearch={closeSearch} />
<SearchResultItem result={result} closeSearch={closeSearch} charLimit={charLimit} />
</li>
))}
</ul>
Expand Down Expand Up @@ -579,11 +583,12 @@ const SearchPlaceholderButton = forwardRef<

export interface SearchProps {
debounceTime?: number;
charLimit?: number;
}
/**
* Component that implements a basic search interface
*/
export function Search({ debounceTime = 500 }: SearchProps) {
export function Search({ debounceTime = 500, charLimit = 64 }: SearchProps) {
const [open, setOpen] = useState(false);
const [searchResults, setSearchResults] = useState<RankedSearchResult[] | undefined>();
const [selectedIndex, setSelectedIndex] = useState(0);
Expand Down Expand Up @@ -662,6 +667,7 @@ export function Search({ debounceTime = 500 }: SearchProps) {
selectedIndex={selectedIndex}
onHoverSelect={setSelectedIndex}
closeSearch={triggerClose}
charLimit={charLimit}
/>
)}
</Dialog.Content>
Expand Down

0 comments on commit db27fa1

Please sign in to comment.