-
Notifications
You must be signed in to change notification settings - Fork 986
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
USWDS - Tooltip: Add top as default position #5228
Conversation
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.
Thanks for your contribution @danbrady! I tested the following markup:
<button type="button" class="usa-button usa-tooltip" title="No position set on this tooltip">No position set</button>
And was able to get the expected behavior.
packages/usa-tooltip/src/index.js
Outdated
@@ -369,7 +369,10 @@ const tooltip = behavior( | |||
[TOOLTIP_TRIGGER](e) { | |||
const { trigger, body } = getTooltipElements(e.target); | |||
|
|||
showToolTip(body, trigger, trigger.dataset.position); | |||
// Default to "top" if `data-position` not specified | |||
const position = trigger.dataset.position || "top"; |
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.
Adding additional note as I remembered this was supposed to be handled in :318
. We check for position in setUpAttributes
and use the default.
Alternatively, we could pass it as a default parameter in showTooltip
:
const showToolTip = (tooltipBody, tooltipTrigger, position="top") => {
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.
You're right, that's a better solution. Updated the PR. Thanks @mejiaj!
b43377a
to
68cd518
Compare
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.
Love having this as a fallback! Working great on my local 👍
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.
FWIW, it appears that removing lines 318-320 as well as 'position' from the returning object on 355 will have no impact to the functionality of the tooltip, even before this PR. The positioning happens when I can update the PR to remove these line and keep the position param with a default value of 'top'. Or, alternatively, update the |
@danbrady removing |
ae10638
to
1c4446b
Compare
1c4446b
to
513c74d
Compare
@mejiaj Ok, updated! Let me know if that's more inline. I kept all the same logic in place for consistency, but safely added default "top" positioning. |
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.
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.
Thank you! |
Summary
Added default positioning. Updated the default position to "top" if
data-position
attribute is not specified.Breaking change
This is not a breaking change.
Related issue
Closes #5218
Problem statement
data-position
omitteddata-position
is not specified, tooltip appears on brokenSolution
data-position
on trigger is setTesting and review
<button type="button" class="usa-button usa-tooltip" title="Show me correctly">Show on top</button>