-
Notifications
You must be signed in to change notification settings - Fork 95
feat: Create Tooltip component #871
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
38 commits
Select commit
Hold shift + click to select a range
9e83e45
create tooltip using css usilities
noelledusahel bddd6df
additional styles
noelledusahel e7614a7
add useState hooks to tooltip component
noelledusahel 69f46d8
add correct styles according to position
noelledusahel 378d9ce
Merge remote-tracking branch 'origin/main' into nb-react-uswds-tooltip
noelledusahel f2e4cb4
additional edits to positioning tooltip body, add element ID to locat…
noelledusahel 41c6529
move all positioning login into a useEffect, register TooltipBodyWidt…
noelledusahel ff163b5
add tooltip ID and remove comments
noelledusahel 7da70f6
remove styles file
noelledusahel 86ed906
add tests to tooltip component
noelledusahel 3d04526
export tooltip component in index.ts
noelledusahel 05455d8
Merge remote-tracking branch 'origin/main' into nb-react-uswds-tooltip
noelledusahel 54d7527
replace reference to tooltipBodyRef.current with variable tooltipBody…
noelledusahel 7a34626
Merge branch 'main' into nb-react-uswds-tooltip
ahobson 3f1e33e
remove package lock file
noelledusahel 112fcd8
create a default tooltip trigger button and create tests for tooltip …
noelledusahel 3034608
begin writing up custom component based off of Link component example
noelledusahel f1128d6
put custom component render in a conditional statement
noelledusahel 40eb2ab
utilize forward ref in customComponent
noelledusahel 559028b
abstract useEffect into a fn, useTooltip
noelledusahel 977604b
move html element role, move event listeners to custom component props
noelledusahel 490e060
Merge remote-tracking branch 'origin/main' into nb-react-uswds-tooltip
noelledusahel f433a51
move isElementInViewport to a utils file
noelledusahel 8139294
correct tests and add test id to tooltip trigger element
noelledusahel 702ebbf
add display name
noelledusahel b672777
add story displayname
noelledusahel ec2525f
corect var name CustomLinkProps
noelledusahel e5ad8f6
Merge remote-tracking branch 'origin/main' into nb-react-uswds-tooltip
noelledusahel a104900
Merge remote-tracking branch 'origin/main' into nb-react-uswds-tooltip
noelledusahel ea89aa0
update tests
noelledusahel dce0062
add data classes prop for css utility classes
noelledusahel 5353144
add keyboard events to tests
noelledusahel ac29ad6
change dataclasses to wrapperclasses and move to trigger element, mov…
noelledusahel f261e00
Merge remote-tracking branch 'origin/main' into nb-react-uswds-tooltip
noelledusahel a0fbe6e
remove className for wrapperclasses from tooltipComponent
noelledusahel 92763d1
apply classname to tooltipTrigger element
noelledusahel a50949c
reformat for storybook addon
noelledusahel e11b26e
Merge remote-tracking branch 'origin/main' into nb-react-uswds-tooltip
noelledusahel File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
import React, { ReactNode } from 'react' | ||
import { fireEvent, render } from '@testing-library/react' | ||
import userEvent from '@testing-library/user-event' | ||
|
||
import { Tooltip } from './Tooltip' | ||
|
||
describe('Tooltip component', () => { | ||
it('renders without errors', () => { | ||
const { queryByTestId } = render( | ||
<Tooltip label="Click me">My Tooltip</Tooltip> | ||
) | ||
expect(queryByTestId('tooltipWrapper')).toBeInTheDocument() | ||
expect(queryByTestId('triggerElement')).toBeInTheDocument() | ||
expect(queryByTestId('tooltipBody')).toBeInTheDocument() | ||
}) | ||
|
||
it('hides tooltip by default', () => { | ||
const { getByTestId } = render( | ||
<Tooltip label="Click me">My Tooltip</Tooltip> | ||
) | ||
expect(getByTestId('tooltipBody')).not.toHaveClass('is-visible') | ||
}) | ||
|
||
it('shows tooltip with mouse event', () => { | ||
const { getByTestId } = render( | ||
<Tooltip label="Click me">My Tooltip</Tooltip> | ||
) | ||
fireEvent.mouseEnter(getByTestId('triggerElement')) | ||
expect(getByTestId('tooltipBody')).toHaveClass('is-visible') | ||
}) | ||
|
||
it('hides tooltip with mouse event', () => { | ||
const { getByTestId } = render( | ||
<Tooltip label="Click me">My Tooltip</Tooltip> | ||
) | ||
fireEvent.mouseLeave(getByTestId('triggerElement')) | ||
expect(getByTestId('tooltipBody')).not.toHaveClass('is-visible') | ||
}) | ||
|
||
it('shows tooltip with keyboard event', () => { | ||
const { getByTestId } = render( | ||
<Tooltip label="Click me">My Tooltip</Tooltip> | ||
) | ||
fireEvent.focus(getByTestId('triggerElement')) | ||
expect(getByTestId('tooltipBody')).toHaveClass('is-visible') | ||
}) | ||
|
||
it('hides tooltip with keyboard event', () => { | ||
const { getByTestId } = render( | ||
<Tooltip label="Click me">My Tooltip</Tooltip> | ||
) | ||
fireEvent.blur(getByTestId('triggerElement')) | ||
expect(getByTestId('tooltipBody')).not.toHaveClass('is-visible') | ||
}) | ||
|
||
describe('with a position prop', () => { | ||
it('applies the default tooltip position', () => { | ||
const { getByTestId } = render( | ||
<Tooltip label="Click me">My Tooltip</Tooltip> | ||
) | ||
expect(getByTestId('tooltipBody')).toHaveClass( | ||
`usa-tooltip__body usa-tooltip__body--top` | ||
) | ||
}) | ||
|
||
it('applies the correct tooltip position when position prop is defined', () => { | ||
const { getByTestId } = render( | ||
<Tooltip position="bottom" label="Click me"> | ||
My Tooltip | ||
</Tooltip> | ||
) | ||
expect(getByTestId('tooltipBody')).toHaveClass( | ||
`usa-tooltip__body usa-tooltip__body--bottom` | ||
) | ||
}) | ||
}) | ||
|
||
describe('with a className prop', () => { | ||
it('applies the className', () => { | ||
const customClass = 'custom-class' | ||
const { getByTestId } = render( | ||
<Tooltip className={customClass} position="left" label="Click me"> | ||
My Tooltip | ||
</Tooltip> | ||
) | ||
expect(getByTestId('triggerElement')).toHaveClass(`${customClass}`) | ||
}) | ||
}) | ||
}) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.