fix(tooltip): Fix Tooltip selectors specificity #2885
Closed
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.
Description
There is a bug in EndUserApp with improper
padding-right
value applied on<GuideTooltip>
. It's caused by accidental change of order of CSS styles from<GuideTooltip>
and<Tooltip>
components.Currently right padding on a
<GuideTooltip>
with close button has 28px (visible below):The intended value from how the styles are written should be 48px (visible below):
The current value is different than intended because
box-content-preview
imports<Tooltip>
component (more details below).It's not clear to me if it should be fixed in
box-ui-elements
or inEndUserApp
, nor what the padding's value should be. For now I'm posting a Draft PR here with intention of having discussion about it.Nitty-gritty
padding-right
value is declared in 2 places:Intended flow
.bdl-GuideTooltip.bdl-Tooltip
and.bdl-Tooltip.with-close-button
match the same element for Guide Tooltip with close button:GuideTooltip.scss
is imported later thanTooltip.scss
(as<GuideTooltip>
imports<Tooltip>
), so it takes precedenceThe result is that the padding should have 48px.
Current flow in EUA
EndUserApp imports
box-content-preview
and it's styles inpreview.css
. Asbox-content-preview
imports<Tooltip>
(but not<GuideTooltip>
) component frombox-ui-elements
,preview.css
stylesheet has it's styles duplicated. Aspreview.css
comes later in EUA's<head>
than main EUA's styles,Tooltip.scss
styles are effectively later in declaration order thanGuideTooltip.css
, even though they should be earlier.The result is that the padding has 28px.
I noticed the bug, when I imported
<GuideTooltip>
inbox-content-preview
and the padding on tooltips changed for no obvious reason. Took me quite a while to identify the problem.Which padding value is intended?
First I guess we should answer which padding value is the intended one? It looks like it should be 48px, but it has been 28px for a while now (a year it seems) and maybe that's what we actually prefer... 馃
Possible solutions
Below I propose 2 different solutions to fix this problem. I assumed 48px is intended value, but they can be modified to use 28px instead.
1. Include
preview.css
earlier in EndUserAppOne solution is changing the order of CSS declarations in EndUserApp's
<head>
so thatpreview.css
comes before main EndUserApp's styles. That would fix the problem both for those tooltip components and any other similar problems that likely already exist or would appear in the future.But it could bring a new array of problems, as we would change order of quite a lot of rules. Different rules might start getting applied to what was applied before in different places of the app.
2. Use
!important
Using
!important
is definitely not a good CSS practice, but it would solve the problem here and be safe to not break other things. It would make further extensions of<GuideTooltip>
harder though.Specificity of
.bdl-GuideTooltip.bdl-Tooltip
selectorThere is one more thing worth to talk about: It's not a good practice that
.bdl-GuideTooltip.bdl-Tooltip
selector uses 2 classes to target an element instead of 1. Those 2 classes will be always applied together (.bdl-GuideTooltip
is passed asclassName
property to<Tooltip>
, which applies it on the same element as has.bdl-Tooltip
class). So.bdl-GuideTooltip.bdl-Tooltip
and.bdl-GuideTooltip
selectors target exactly the same set of elements. There is a good reason why methodologies like BEM exist and recommend always using single class selectors (other than when you have modifiers) and we break that good practice here.I understand it was probably done to equal the specificity of
.bdlTooltip.with-close-button
selector, but there is another solution we could use - re-declaring.with-close-button
again inGuideTooltip.scss
: