USWDS - Tooltip: Add top as default position#5228
Conversation
There was a problem hiding this comment.
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.
|
|
||
| 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.
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.
You're right, that's a better solution. Updated the PR. Thanks @mejiaj!
b43377a to
68cd518
Compare
mahoneycm
left a comment
There was a problem hiding this comment.
Love having this as a fallback! Working great on my local 👍
|
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. |
|
Thank you! |



Summary
Added default positioning. Updated the default position to "top" if
data-positionattribute is not specified.Breaking change
This is not a breaking change.
Related issue
Closes #5218
Problem statement
data-positionomitteddata-positionis not specified, tooltip appears on brokenSolution
data-positionon trigger is setTesting and review
<button type="button" class="usa-button usa-tooltip" title="Show me correctly">Show on top</button>