necolas / react-native-web

Cross-platform React UI packages
https://necolas.github.io/react-native-web
MIT License
21.66k stars 1.79k forks source link

Tooltip Component Cut Off or Not Fully Visible When Hovering Truncated Text in FlatList #2533

Closed eliyahu-kriel closed 1 year ago

eliyahu-kriel commented 1 year ago

Is there an existing issue for this?

Describe the issue

I encountered an issue while implementing a table using FlatList in react-native-web. When the text of an item is long and gets truncated, the tooltip component I created does not display properly when hovering over the first few elements in the list. The tooltip gets cut off or does not appear entirely.

Screenshot 2023-06-01 at 8 19 51

on the last element - work great Screenshot 2023-06-01 at 8 20 19

you can see all the code in the sandbox

Expected behavior

The tooltip component should be displayed properly when hovering over the truncated text, regardless of the item's position in the list. The full text should be visible in the tooltip without any cutoff or display issues.

Steps to reproduce

  1. Create a table-like structure using FlatList in react-native-web.
  2. Include a tooltip component that shows the full text of a truncated item when hovered.
  3. Populate the table with items where the text of one or more fields is long enough to be truncated.
  4. Observe the behavior when hovering over the truncated text in the first few elements of the list.

Test case

https://codesandbox.io/s/loving-torvalds-d0mwdg?file=/src/App.js

Additional comments

necolas commented 1 year ago

Overflow is hidden on almost all elements, so generally things like tooltips need to be rendered in a separate layer (like modals are) that can be positioned over the app.

eliyahu-kriel commented 1 year ago

but i want the tooltip will be on the exactly hovered element, how can i achieve it without complex calculations? if its in a separate layer i have to do some x,y calculations, isn't?

alzalabany commented 1 year ago

@eliyahu-kriel not really too complex; just pass parentElm to your tooltip; and use createPortal to escape dom

  const {x,y} = parentElm.getBoundingClientRect();
  return createPortal(
    <Pressable onPress={onClickOutside} style={[StyleSheet.absoluteFill, {backgroundColor: 'rgba(0,0,0,.5)'}]}>
        <div
        style={{
          top: y,
          left: x,
        }}>
           // .... your code
         </div>
    </Pressable>,
    document.body
  );