-
Notifications
You must be signed in to change notification settings - Fork 97
Added className prop support #56
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -53,6 +53,29 @@ describe('<Tippy />', () => { | |
| expect(tip.popper.querySelector('strong')).not.toBeNull() | ||
| }) | ||
|
|
||
| test('custom class name get added to DOM', () => { | ||
| const className = 'hello' | ||
| const { container } = render( | ||
| <Tippy content="tip content" className={className}> | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you add a test that checks the add/remove when updating the state? e.g. starts with className A, after updating, ends with className B, but doesn't still contain className A. the useEffect looks correct to me anyway but still :-)
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm afraid I may need a hand here. Two things, actually:
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To be honest, I don't really know either. There seems to be missing documentation for this or maybe I can't find it??? 😢
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. useLayoutEffect runs synchronously after each render, so it's good for things like DOM manipulation outside React (like plain DOM api, or jQuery). I'm gonna take a look at this PR today
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I changed it back to I have no idea how to fix it either.
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I will go ahead and merge this since it's working fine in the browser and logic looks correct 🤷♂️ If we can figure out how to test it, make a PR |
||
| <button /> | ||
| </Tippy>, | ||
| ) | ||
| const tip = container.querySelector('button')._tippy | ||
| expect(tip.popper.querySelector(`.${className}`)).not.toBeNull() | ||
| }) | ||
|
|
||
| test('custom class name get added to DOM', () => { | ||
| const classNames = 'hello world' | ||
| const { container } = render( | ||
| <Tippy content="tip content" className={classNames}> | ||
| <button /> | ||
| </Tippy>, | ||
| ) | ||
| const tip = container.querySelector('button')._tippy | ||
| expect(tip.popper.querySelector('.hello')).not.toBeNull() | ||
| expect(tip.popper.querySelector('.world')).not.toBeNull() | ||
| }) | ||
|
|
||
| test('unmount destroys the tippy instance and allows garbage collection', () => { | ||
| const { container, unmount } = render( | ||
| <Tippy content="tooltip"> | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not the prettiest test, but it helped to confirm the classes were being dynamically added/removed from the tippy element.