react-select icon indicating copy to clipboard operation
react-select copied to clipboard

react-select inside radix-ui dialog not working properly

Open hadson172 opened this issue 2 years ago • 10 comments

In short, when I place react-select inside radix-ui dialog/popover and when focus is on react-select I am not able to close dialog using ESC. Additionaly "tab" traversal is not working properly. Pressing tab does not traverse between two selects Here is a source code: https://codesandbox.io/s/trusting-dewdney-485wkd?file=%2Fsrc%2FApp.tsx

hadson172 avatar Aug 20 '23 16:08 hadson172

I have also meet this issue!

NguyenTrung1995 avatar Aug 23 '23 04:08 NguyenTrung1995

@hadson172 @NguyenTrung1995 The tab traversal issue must be caused by radix-ui. react-select does nothing on Tab as long as the menu isn't open. With e.g. react-focus-trap I could not replicate the issue.

Rall3n avatar Aug 23 '23 06:08 Rall3n

Workaround that works for my use case until this gets fixed in radix-ui:

const onBlurWorkaround = (event: React.FocusEvent<HTMLInputElement>) => {
  const element = event.relatedTarget;
  if (element && (element.tagName === 'A' || element.tagName === 'BUTTON' || element.tagName === 'INPUT')) {
    (element as HTMLElement).focus();
  }
};

philsp avatar Oct 01 '23 14:10 philsp

Workaround that works for my use case until this gets fixed in radix-ui:

const onBlurWorkaround = (event: React.FocusEvent<HTMLInputElement>) => {
  const element = event.relatedTarget;
  if (element && (element.tagName === 'A' || element.tagName === 'BUTTON' || element.tagName === 'INPUT')) {
    (element as HTMLElement).focus();
  }
};

Alhamdulillah, this works like magic brother 😃just add this on react-select onBlur prop btw

raihan-suryanom avatar Nov 13 '23 09:11 raihan-suryanom

@philsp Thanks for the workaround. Is there a ticket created for radix-ui that I can follow?

abartolo avatar Dec 07 '23 22:12 abartolo

This workaround works great for the TAB problem! is there a workaround for the ESC problem mentioned on the original issue?

ss-ravi avatar Apr 24 '24 07:04 ss-ravi

Workaround that works for my use case until this gets fixed in radix-ui:

const onBlurWorkaround = (event: React.FocusEvent<HTMLInputElement>) => {
  const element = event.relatedTarget;
  if (element && (element.tagName === 'A' || element.tagName === 'BUTTON' || element.tagName === 'INPUT')) {
    (element as HTMLElement).focus();
  }
};

Amazing Sir! I had to login to say thank you so much

bon3495 avatar Apr 26 '24 06:04 bon3495

Workaround that works for my use case until this gets fixed in radix-ui:

const onBlurWorkaround = (event: React.FocusEvent<HTMLInputElement>) => {
  const element = event.relatedTarget;
  if (element && (element.tagName === 'A' || element.tagName === 'BUTTON' || element.tagName === 'INPUT')) {
    (element as HTMLElement).focus();
  }
};

Have the same issue too. This approach is good but I still face the other problem when the next focus element is not a standard input element (in my case is "RadioGroup"). so I made some modify to following:

const onBlurWorkaround = (event: React.FocusEvent<HTMLInputElement>) => {
  const element = event.relatedTarget as HTMLElement
  if (element?.getAttribute('role') === 'dialog') return
  element?.focus()
}

I hope this can help someone have the same issue with me. and hope someday this issue can be fixed too.

jubeatt avatar May 23 '24 07:05 jubeatt