Skip to content

Commit

Permalink
fix(tag-input): correcting some type issues and removing unused depen…
Browse files Browse the repository at this point in the history
…dencies
  • Loading branch information
JaleelB committed Jul 31, 2024
1 parent 247747e commit f0b8bbb
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 17 deletions.
5 changes: 5 additions & 0 deletions .changeset/bright-timers-mix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'emblor': patch
---

correcting some type issues and removing unused dependencies
19 changes: 10 additions & 9 deletions packages/emblor/src/tag/autocomplete.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useCallback, useEffect, useMemo, useRef, useState } from 'react';
import React, { useCallback, useEffect, useRef, useState } from 'react';
// import { Command, CommandList, CommandItem, CommandGroup, CommandEmpty } from '../ui/command';
import { TagInputStyleClassesProps, type Tag as TagType } from './tag-input';
import { cn } from '../utils';
Expand Down Expand Up @@ -52,12 +52,13 @@ export const Autocomplete: React.FC<AutocompleteProps> = ({

// Close the popover when clicking outside of it
useEffect(() => {
const handleOutsideClick = (event) => {
const handleOutsideClick = (event: MouseEvent | TouchEvent | React.MouseEvent | React.TouchEvent) => {
if (
isPopoverOpen &&
triggerContainerRef.current &&
!triggerContainerRef.current.contains(event.target) &&
!popoverContentRef.current.contains(event.target)
popoverContentRef.current &&
!triggerContainerRef.current.contains(event.target as Node) &&
!popoverContentRef.current.contains(event.target as Node)
) {
setIsPopoverOpen(false);
}
Expand Down Expand Up @@ -139,7 +140,7 @@ export const Autocomplete: React.FC<AutocompleteProps> = ({
<div
className={cn(
'flex h-full w-full flex-col overflow-hidden rounded-md bg-popover text-popover-foreground',
classStyleProps.command,
classStyleProps?.command,
)}
>
<Popover open={isPopoverOpen} onOpenChange={handleOpenChange} modal={usePortal}>
Expand All @@ -157,7 +158,7 @@ export const Autocomplete: React.FC<AutocompleteProps> = ({
variant="ghost"
size="icon"
role="combobox"
className={cn(`hover:bg-transparent ${!inlineTags ? 'ml-auto' : ''}`, classStyleProps.popoverTrigger)}
className={cn(`hover:bg-transparent ${!inlineTags ? 'ml-auto' : ''}`, classStyleProps?.popoverTrigger)}
onClick={() => {
setIsPopoverOpen(!isPopoverOpen);
}}
Expand All @@ -184,7 +185,7 @@ export const Autocomplete: React.FC<AutocompleteProps> = ({
side="bottom"
align="start"
forceMount
className={cn(`p-0 relative`, classStyleProps.popoverContent)}
className={cn(`p-0 relative`, classStyleProps?.popoverContent)}
style={{
top: `${popooverContentTop}px`,
marginLeft: `calc(-${popoverWidth}px + 36px)`,
Expand Down Expand Up @@ -236,7 +237,7 @@ export const Autocomplete: React.FC<AutocompleteProps> = ({
<div
key={autocompleteOptions.length}
role="group"
className={cn('overflow-y-auto overflow-hidden p-1 text-foreground', classStyleProps.commandGroup)}
className={cn('overflow-y-auto overflow-hidden p-1 text-foreground', classStyleProps?.commandGroup)}
style={{
minHeight: '68px',
}}
Expand All @@ -250,7 +251,7 @@ export const Autocomplete: React.FC<AutocompleteProps> = ({
role="option"
className={cn(
'relative flex cursor-pointer select-none items-center rounded-sm px-2 py-1.5 text-sm outline-none aria-selected:bg-accent aria-selected:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50 hover:bg-accent',
classStyleProps.commandItem,
classStyleProps?.commandItem,
)}
data-value={option.text}
onClick={() => toggleTag(option)}
Expand Down
9 changes: 4 additions & 5 deletions packages/emblor/src/tag/tag-input.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -340,11 +340,10 @@ const TagInput = React.forwardRef<HTMLInputElement, TagInputProps>((props, ref)
// ? autocompleteOptions?.filter((option) => autocompleteFilter(option.text))
// : autocompleteOptions;
const filteredAutocompleteOptions = useMemo(() => {
if (autocompleteFilter) {
return autocompleteOptions.filter((option) => autocompleteFilter(option.text));
}
return autocompleteOptions.filter((option) => option.text.toLowerCase().includes(inputValue.toLowerCase()));
}, [inputValue, autocompleteOptions, autocompleteFilter]);
return (autocompleteOptions || []).filter((option) =>
option.text.toLowerCase().includes(inputValue ? inputValue.toLowerCase() : ''),
);
}, [inputValue, autocompleteOptions]);

const displayedTags = sortTags ? [...tags].sort() : tags;

Expand Down
7 changes: 4 additions & 3 deletions packages/emblor/src/tag/tag-popover.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,13 @@ export const TagPopover: React.FC<TagPopoverProps> = ({

// Close the popover when clicking outside of it
useEffect(() => {
const handleOutsideClick = (event) => {
const handleOutsideClick = (event: MouseEvent | TouchEvent | React.MouseEvent | React.TouchEvent) => {
if (
isPopoverOpen &&
triggerContainerRef.current &&
!triggerContainerRef.current.contains(event.target) &&
!popoverContentRef.current.contains(event.target)
popoverContentRef.current &&
!triggerContainerRef.current.contains(event.target as Node) &&
!popoverContentRef.current.contains(event.target as Node)
) {
setIsPopoverOpen(false);
}
Expand Down

0 comments on commit f0b8bbb

Please sign in to comment.