You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have input inside of the Popover.Trigger and when pressing the Space key it triggers the keyboard interactions so I disabled it from the Popover.Trigger but the input inside of the component still fires the interaction and I can't disable pressing Space because duhh it is an input.
Any ideas about how to fix this issue?
I tried controlling the input and slicing but if the cursor is in the middle when pressing space it push the cursor to the end
<PopoverTriggerclassName="relative w-full"><Inputvalue={searchQuery}onChange={(e)=>setSearchQuery(e.target.value)}onKeyDown={(e)=>{constcursorIndex=e.currentTarget.selectionStart;// I have to use this workaround because Radix doesn't support disabling keyboard actions and I have input so disabling the space can't be an optionif(e.key===" "){e.preventDefault();setSearchQuery((prev)=>prev.slice(0,cursorIndex!)+" "+prev.slice(cursorIndex!),);}}}/></PopoverTrigger>
const[isOpen,setIsOpen]=useState(false);constinputRef=useRef<HTMLInputElement|null>(null);const[inputIndex,setInputIndex]=useState(0);useEffect(()=>{inputRef.current!.selectionStart=inputIndex+1;inputRef.current!.selectionEnd=inputIndex+1;// eslint-disable-next-line react-hooks/exhaustive-deps},[searchQuery]);<PopoveronOpenChange={(open)=>setIsOpen(open)}open={isLoading ? false : isOpen}><PopoverTriggerclassName="relative w-full"onClick={(e)=>{consttargetId: string|null|undefined=(e.targetasElement).id;if(targetId&&targetId==="popoverInput"&&isOpen){e.preventDefault();}}}onFocus={()=>{setIsOpen(true);}}><Inputid="popoverInput"ref={inputRef}type="text"value={searchQuery}onChange={(e)=>setSearchQuery(e.target.value)}placeholder="Kategori seçiniz"disabled={isLoading}onKeyDown={(e)=>{// Another solution is to not use PopoverTrigger// I have to use this workaround because Radix doesn't support disabling keyboard actions and I have input so disabling the space can't be an option// This works by handling the cursor automaticallyconstcursorIndexStart=e.currentTarget.selectionStart!;constcursorIndexEnd=e.currentTarget.selectionEnd!;constisSelect=!(cursorIndexStart===cursorIndexEnd);constisSelectAll=cursorIndexStart+cursorIndexEnd===e.currentTarget.value.length;setInputIndex(isSelect&&!isSelectAll
? cursorIndexStart-1
: cursorIndexStart,);if(e.key===" "){e.preventDefault();setSearchQuery((prev)=>prev.slice(0,cursorIndexStart)+" "+prev.slice(cursorIndexStart),);}}}/>// ...</PopoverTrigger><PopoverContent
...
onOpenAutoFocus={(e)=>{e.preventDefault();}}>// Content Here...</PopoverContent></Popover>
issues:
Can't tab into the popover, you can tab into the input.
Complicated. I disabled a few features and handled them myself.
I cut the example out of context I hope the code is understandable
EDIT:
I suggest you figure out a solution yourself because there are cases you wouldn't understand unless you try it out.
I already worked on my personal case and have a kinda solution. I downloaded their(radixui) internal popover packages and codes from github. And I'm able to solve my specific case. At the same time I also downloaded their (radixui) hovercard codes and manipulated the code for my specific case. I found out that hover card's code is more flexible to manipulate than popover. I'm still testing those changes, once it's done. I will use it in my project.
Thanks for sharing some knowledge.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
I have input inside of the Popover.Trigger and when pressing the Space key it triggers the keyboard interactions so I disabled it from the Popover.Trigger but the input inside of the component still fires the interaction and I can't disable pressing Space because duhh it is an input.
Any ideas about how to fix this issue?
Beta Was this translation helpful? Give feedback.
All reactions