question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Component Tooltips Should Provide Prop Info

See original GitHub issue

The Problem: When adding a component to a page, it’s cumbersome to need to open the component to view which props exist, and which have default values. It would be more ergonomic for the component’s tooltip to show all of the props available (and any JSDoc markup for each prop).

(For the purposes of this explanation, here's an example component (click to reveal) with a few example props that I will refer to below):

Currently, when you hover a component in a page's markup without any ` @component ` tag present in the markup, you get something like this. It doesn't provide any information about the component's props:

image

If you want that information visible outside of the component, the closest thing we get to this is the error tooltip that shows when a component is missing some props that don’t have default values and thus are undefined by the component. These are required and expected to be provided when the component is used:

image

This isn’t terribly easy to read to begin with, especially with numerous/complex props, but it does convey that the language server is already aware of the expected props/types on the component, and which ones are optional.

We actually get less no information about the component’s props when the error highlighting disappears. Now I need to open the component to go see what other props/methods are available on it… not a great experience:

image

Ironically, the props you actually do provide to the component show their JSDoc comments in their own tooltips:

image

This is weird, because if I’m already passing the prop name in and providing the values, I’m probably past the point of needing the JSDoc comment to guide me.

A solution: I’d like to see the component tag’s tooltip able to provide all of the prop information on hover, along with any JSDoc comments that may exist for each prop. Here’s a crude example (forgive my copy/paste-into-Paint skills here): image

Alternatives: The @component comment tag is capable of providing this to some degree, but is considerably more verbose. Moreover, the language server is already aware of these props and types, so we shouldn’t ask the user to type out all the JSDoc syntax within a @component tag, when a comment above each prop could get you 90% of the way there.

Issue Analytics

  • State:open
  • Created 2 years ago
  • Reactions:2
  • Comments:10 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
Tymekcommented, Jan 25, 2022

Writing in TS, I care about prop autocomplete much more than about component tooltip, and second version from comment above is more desirable because it’s DRY and with TS you can skip most of the @type {Boolean} [gridlines=true] – noise because it’s inferred.

1reaction
jasonlyu123commented, Dec 31, 2021

It should be possible to do. But I think there should a config to toggle this behaviour. It could get out of hand pretty easily. Especially when dealing with a component library. And I would prefer to just ctrl+I/ctrl+space to trigger completion and go through the props to see the individual docs.

Combine with the mentioned above, we could have a multiple-choice config:

  1. fallback, only show it when there’s no @component comment
  2. combine, show both
  3. disable
Read more comments on GitHub >

github_iconTop Results From Across the Web

React Tooltip component - Material UI - MUI
Tooltips display informative text when users hover over, focus on, or tap an element. When activated, Tooltips display a text label identifying an...
Read more >
Building a tooltip component - web.dev
A tooltip should contain non-interactive supplemental information, while a toggletip can contain interactivity and important information. The ...
Read more >
Controlling tooltips & pop-up menus with components in React
Use compound components to control tooltips and pop-up menus in your React applications, helping you keep your user interface clean and ...
Read more >
Tooltip - Examples - Components - Atlassian Design System
The tooltip component accepts a component prop, which enables users to customize the look and feel of the tooltip area. Hover Over Me....
Read more >
How To Make an Extremely Reusable Tooltip Component ...
It controls what content will be inside the tooltip bubble with props.content; It controls where the bubble will appear using the value passed ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found