-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(components): add option to delete input of text-input and lineage-filter input with x and sort text-input datalist options #631
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -1,5 +1,5 @@ | ||||||||||||||||
import { type FunctionComponent } from 'preact'; | ||||||||||||||||
import { useContext, useRef } from 'preact/hooks'; | ||||||||||||||||
import { useContext, useRef, useState } from 'preact/hooks'; | ||||||||||||||||
import z from 'zod'; | ||||||||||||||||
|
||||||||||||||||
import { fetchLineageAutocompleteList } from './fetchLineageAutocompleteList'; | ||||||||||||||||
|
@@ -45,6 +45,9 @@ const LineageFilterInner: FunctionComponent<LineageFilterInnerProps> = ({ | |||||||||||||||
|
||||||||||||||||
const inputRef = useRef<HTMLInputElement>(null); | ||||||||||||||||
|
||||||||||||||||
const [hasInput, setHasInput] = useState<boolean>(!!initialValue); | ||||||||||||||||
const [inputValue, setInputValue] = useState(initialValue || ''); | ||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||
|
||||||||||||||||
const { data, error, isLoading } = useQuery( | ||||||||||||||||
() => fetchLineageAutocompleteList(lapis, lapisField), | ||||||||||||||||
[lapisField, lapis], | ||||||||||||||||
|
@@ -73,6 +76,8 @@ const LineageFilterInner: FunctionComponent<LineageFilterInnerProps> = ({ | |||||||||||||||
composed: true, | ||||||||||||||||
}), | ||||||||||||||||
); | ||||||||||||||||
setHasInput(value !== undefined); | ||||||||||||||||
setInputValue(value || ''); | ||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's move this to the first line of this function - then you can even delete invalid input. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||
} | ||||||||||||||||
}; | ||||||||||||||||
|
||||||||||||||||
|
@@ -85,15 +90,32 @@ const LineageFilterInner: FunctionComponent<LineageFilterInnerProps> = ({ | |||||||||||||||
|
||||||||||||||||
return ( | ||||||||||||||||
<> | ||||||||||||||||
<input | ||||||||||||||||
type='text' | ||||||||||||||||
class='input input-bordered w-full' | ||||||||||||||||
placeholder={placeholderText !== undefined ? placeholderText : lapisField} | ||||||||||||||||
onInput={onInput} | ||||||||||||||||
ref={inputRef} | ||||||||||||||||
list={lapisField} | ||||||||||||||||
value={initialValue} | ||||||||||||||||
/> | ||||||||||||||||
<div className='relative w-full'> | ||||||||||||||||
<input | ||||||||||||||||
type='text' | ||||||||||||||||
class='input input-bordered w-full pr-10' | ||||||||||||||||
placeholder={placeholderText !== undefined ? placeholderText : lapisField} | ||||||||||||||||
onInput={onInput} | ||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
And change line 68 from const onInput = () => {
const value = inputRef.current?.value === '' ? undefined : inputRef.current?.value; to const onInput = (value?: string) => { |
||||||||||||||||
ref={inputRef} | ||||||||||||||||
list={lapisField} | ||||||||||||||||
value={inputValue} | ||||||||||||||||
/> | ||||||||||||||||
{hasInput && ( | ||||||||||||||||
<button | ||||||||||||||||
type='button' | ||||||||||||||||
name='✕' | ||||||||||||||||
className='absolute top-1/2 right-2 transform -translate-y-1/2 text-gray-500 hover:text-gray-700' | ||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. See https://daisyui.com/components/input/#text-input-with-icon-inside for a better way how to get the icon inside the "input field" |
||||||||||||||||
onClick={() => { | ||||||||||||||||
if (inputRef.current) { | ||||||||||||||||
inputRef.current.value = ''; | ||||||||||||||||
onInput(); | ||||||||||||||||
} | ||||||||||||||||
}} | ||||||||||||||||
Comment on lines
+108
to
+113
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't like the side effects of this - I' propose to implement it as:
Suggested change
(see other comments for how to adapt the rest) |
||||||||||||||||
> | ||||||||||||||||
✕ | ||||||||||||||||
</button> | ||||||||||||||||
)} | ||||||||||||||||
</div> | ||||||||||||||||
<datalist id={lapisField}> | ||||||||||||||||
{data.map((item) => ( | ||||||||||||||||
<option value={item} key={item} /> | ||||||||||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hasInput
is redundant - it can be computed frominputValue