-
Notifications
You must be signed in to change notification settings - Fork 3
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
Tooltip #128
Tooltip #128
Conversation
Also did a drive-by breadcrumb alignment fix (#127). |
52e7b36
to
650b7ed
Compare
Rebased and moved Tooltip docz page into Overlays section. |
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.
This looks good and functions as I'd expect. Let's get this merged in once the conflicts are resolved.
There is a warning about invalid DOM nesting which I'd like to handle at some point in the future with another PR. It could have undesired outcomes in different browsers.
For example, currently, if you apply a tooltip in a button and have a button within that tooltip (see doc example), technically you have illegally nested buttons as far as browsers are concerned. But the way we ultimately render the component removes the nested structure in the DOM but only after the browser gives us a console warning. Since, at the end of the day, we aren't maintaining an illegal nesting structure, I propose we make an issue for this and fix it later.
Darn. Thought I'd found a way around that. I may take one more look at that before merging. |
Add extractComponentFromChildren() to new utils.js, use in components that ignore their children.
650b7ed
to
4b519a1
Compare
Overview
Add a Tooltip component.
Per #28, this component relies on popper.js (more specifically tooltip.js, which relies on popper.js).
Most React libraries that provide support for adornments like tooltips take a HOC approach or require inverted syntax like:
I struggle conceptually with those approaches. Adornments seem like they ought to be subordinately attached to their reference components somehow, rather than wrapped around them. So I decided to author our Tooltip component to be nested within its reference component. This solution, at least in its current state, has its shortcomings, but is functional and I think worth trying out.
Usage
Requirements
data-tooltip
attribute to reference component.<img>
,<input>
).Box
.Tooltip only supports a single child that must be a string.Future work: Support arbitrary jsx children.Component authoring
When authoring a component that ignores
props.children
(eg,Pill
,Swatch
) and might be used with a Tooltip, your must do something like the following or you'll ignore the Tooltip, too:Checklist
Are there any of the following in this PR?
If one of the above is checked...
Upgrade Instructions
Demo
Notes
I had to parameterize Tooltip.js somewhat to make it work as the basis of this component:
I added a
utils.js
file with anextractComponentFromChildren()
function. Not sure if I placedutils.js
in the appropriate place in the src folder tree.Future work might consider alternate tooltip libraries, eg:
Closes #28