Skip to content
This repository has been archived by the owner on Mar 4, 2020. It is now read-only.

feat(Tooltip): base implementation #1455

Merged
merged 36 commits into from
Jun 12, 2019
Merged

Conversation

mnajdova
Copy link
Contributor

@mnajdova mnajdova commented Jun 5, 2019

Fix #1453 - add Tooltip component.
A tooltip displays information related to an element when the element receives keyboard focus, or the mouse hovers over it. The Tooltip component has the following API:

Common Stardust props

  • accessibility
  • styles
  • variables
  • className
  • content - the content that will appear inside the tooltip
  • children

Custom component props

  • target - the element to which the tooltip is associated with
  • mouseLeaveDelay - delay in ms for the mouse leave event, before the tooltip will be closed.
  • pointing - whether the tooltip should show pointer towards the target
  • align - alignment for the tooltip. Can have one of the following values: 'top' | 'bottom' | 'start' | 'end' | 'center'
  • mountNode - Existing element the tooltip should be bound to.
  • position - has one of the following value: 'above' | 'below' | 'before' | 'after'. It has higher priority than align. If position is vertical ('above' | 'below') and align is also vertical ('top' | 'bottom') or if both position and align are horizontal ('before' | 'after' and 'start' | 'end' respectively), then provided value for 'align' will be ignored and 'center' will be used instead.
    With this API the component will be similar to the Popup component, and it will be easy for the users to learn the new component's API.

TODO:

  • add Tooltip tests

@codecov
Copy link

codecov bot commented Jun 5, 2019

Codecov Report

Merging #1455 into master will decrease coverage by 0.19%.
The diff coverage is 55.2%.

Impacted file tree graph

@@            Coverage Diff            @@
##           master    #1455     +/-   ##
=========================================
- Coverage   73.63%   73.44%   -0.2%     
=========================================
  Files         808      818     +10     
  Lines        6092     6179     +87     
  Branches     1774     1774             
=========================================
+ Hits         4486     4538     +52     
- Misses       1601     1636     +35     
  Partials        5        5
Impacted Files Coverage Δ
packages/react/src/lib/positioner/Popper.tsx 89.13% <ø> (ø) ⬆️
packages/react/src/index.ts 100% <ø> (ø) ⬆️
...hemes/teams/components/Tooltip/tooltipVariables.ts 0% <0%> (ø)
...rast/components/Tooltip/tooltipContentVariables.ts 0% <0%> (ø)
...gh-contrast/components/Tooltip/tooltipVariables.ts 0% <0%> (ø)
...dark/components/Tooltip/tooltipContentVariables.ts 0% <0%> (ø)
...eams/components/Tooltip/tooltipContentVariables.ts 0% <0%> (ø)
...hemes/teams/components/Popup/popupContentStyles.ts 20% <0%> (-3.08%) ⬇️
...es/react/src/components/Tooltip/TooltipContent.tsx 100% <100%> (ø)
...s/teams/components/Tooltip/tooltipContentStyles.ts 20% <20%> (ø)
... and 14 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 14a91bc...38c0e6f. Read the comment docs.

@mnajdova mnajdova changed the title [WIP] - Tooltip base component feat(Tooltip): base implementation Jun 6, 2019
@codepretty codepretty requested a review from notandrew June 6, 2019 19:31
@codepretty
Copy link
Collaborator

@mnajdova thanks for starting on this!! There are just a couple things I noticed..

  1. the pointing tooltip needs to have an svg beak for the pointer - @notandrew has the asset and can give to you
  2. should pointing be the default? it seems to be the most common way i see tooltips
  3. i don't think tooltips should ever render off page even if an offset is set?
    image
  4. i might just not have noticed this, but is there a way to specify one of the common color schemes? It might be nice to have those as example usages if possible :)
  5. are nested tooltips a common paradigm?

@jurokapsiar
Copy link
Contributor

Similarly to reakit tooltip or Fabric, we will need to have a reference between the tooltip between the tooltip and trigger, most probably using aria-describedby. When rendered it should look something like this:

<button aria-describedby="tooltip1">I am a button</button>
<div id="tooltip1">I am a tooltip</div>

Let's discuss how the API should look like, I would propose to make the id prop of Tooltip required so that the user would need to provide the ID. In the jsdoc comment for the id prop, we can say something like "put the tooltip id in the aria-describedby prop"

We can later (out of this PR) have some helper hook:

let tooltip = useTooltip();
<Tooltip
    {...tooltip.tooltipProps}
    trigger={<Button content="I am a button" {...tooltip.triggerProps} />}
    content={{
      content: "I am a tooltip"
    }}
  />

And for the actionable components:

<Button content="I am a button" tooltip="I am a tooltip" />

which would automatically render the Tooltip and Button with appropriate pros

@mnajdova
Copy link
Contributor Author

mnajdova commented Jun 10, 2019

@jurokapsiar if the id is necessary, we can make it in required and hoist it in the Tooltip component. Then in the behavior we can specify this prop as id in the content and aria-describedby in the trigger. Wouldn't this be sufficient for all cases? We can make the adding of the required props in the behavior, I don't see why we need from the client to make this correlation. Am I missing something?

I see the tooltipBehavior as something like this:

const tooltipBehavior: Accessibility = (props: any) => {
  const { id } = props
  return {
    attributes: {
      trigger: {
        'aria-describedby': id,
      },
      content: {
        id,
      },
    },
  }
}

@mnajdova
Copy link
Contributor Author

mnajdova commented Jun 10, 2019

@codepretty answers to your points

@mnajdova thanks for starting on this!! There are just a couple things I noticed..

the pointing tooltip needs to have an svg beak for the pointer - @notandrew has the asset and can give to you

Currently the beak is implemented exactlly as it is in the Popup. Are these two different? Let's align them both in a separate PR for red-lining the component, as this is base implementation

should pointing be the default? it seems to be the most common way i see tooltips

I was thinking the same, but as in the Popup this prop was by default false, I added that as a default. I will change this to be true by default in the Tooltip. If people are agains this, we can export the Tooltip on the client's side to have this to be true by default

i don't think tooltips should ever render off page even if an offset is set?

Let me try to remove this option in the alignment of the Tooltip, I agree is not something typical for the Tooltip.

i might just not have noticed this, but is there a way to specify one of the common color schemes? It might be nice to have those as example usages if possible :)

Would rather wait for designs for something like that before adding examples in the docs, but yes if there are use cases like this, would be happy to add more examples

are nested tooltips a common paradigm?

NO! Very valid point, will remove that example :)

@jurokapsiar
Copy link
Contributor

we did some testing on our prototypes and it looks like we will need to change the approach: the div containing tooltip text will always need to be present in the DOM and the trigger elements will need to point to it using aria-describedby. focus/hover should then only change the visibility. let's discuss offline how this can be achieved.

Regarding your response - yes, it can work, if we are ok with modifying the trigger.
There is one more case I need to think about - if the user provides element/component with aria-describedby - then the tooltip id should probably be added to the beginning of trigger's aria-describedby.

Copy link
Collaborator

@bmdalex bmdalex left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 great job!

@@ -127,7 +127,15 @@ const Popper: React.FunctionComponent<PopperProps> = props => {
popperRef.current = createPopper(targetRef.current, contentRef.current, options)
},
// TODO review dependencies for popperHasScrollableParent
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this comment still necessary - I mean, if these are reviewed, we may remove TODO comment :) or there are some checks that you still expect to be made?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure, this was here before. I found this issue while working on the tooltip, so I added the triggerRef there as well. I think is @Bugaa92 's call about whether it is safe to remove it

import { useBooleanKnob } from '@stardust-ui/docs-components'

const TooltipOpenExample = () => {
const [open, setOpen] = useBooleanKnob({ name: 'open-c', initialValue: true })
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const [open, setOpen] = useBooleanKnob({ name: 'open-c', initialValue: true })
const [open, setOpen] = useBooleanKnob({ name: 'open', initialValue: true })

After #1489 will be merged

import { useBooleanKnob } from '@stardust-ui/docs-components'

const TooltipOpenExample = () => {
const [open, setOpen] = useBooleanKnob({ name: 'open-c', initialValue: true })
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const [open, setOpen] = useBooleanKnob({ name: 'open-c', initialValue: true })
const [open, setOpen] = useBooleanKnob({ name: 'open', initialValue: true })

After #1489 will be merged


const TooltipExamplePosition = () => {
const [positionAndAlign] = useSelectKnob({
name: 'position-align-c',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
name: 'position-align-c',
name: 'position-align',

After #1489 will be merged


const TooltipExamplePosition = () => {
const [positionAndAlign] = useSelectKnob({
name: 'position-align-s',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
name: 'position-align-s',
name: 'position-align',

After #1489 will be merged

@mnajdova mnajdova merged commit 840a3ea into master Jun 12, 2019
@delete-merged-branch delete-merged-branch bot deleted the feat/tooltip-base-component branch June 12, 2019 15:11
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[RFC] Tooltip - base component
6 participants