fix: fixed Chip
"shadow" and height issue
#4461
Open
+22
−24
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.
Motivation
There is an issue with the
Chip
component when aChip
withmode="outlined"
is used next to one withmode="flat"
(see screenshot). TheChip
withmode="flat"
displays a kind of "shadow" at the bottom.This problem is caused by the
Surface
component, which splits styles provided via props intoouterLayerViewStyles
andinnerLayerViewStyles
. Specifically, it is caused by thebackgroundColor
, which has the same value in bothouterLayerViewStyles
andinnerLayerViewStyles
(see below, reference):A
Chip
withmode="outlined"
is2dp
larger in width and height than one withmode="flat"
due to itsborderWidth
of1dp
. When both modes are placed next to each other, the outerView
of theSurface
component adjusts to fill the height difference, but the innerView
does not. Since the background color for a disabledChip
uses RGBA (with opacity), the inner and outer background colors create overlapping layers, resulting in the visible "shadow" at the bottom.Possible solutions
1. Adding
flexGrow: 1
to theSurface
used insideChip
componentAdding
flexGrow: 1
would resolve the issue by allowing the innerView
of theSurface
to grow and match the height of the outerView
. However, because outerLayerStylesProperties includesflexGrow
, it won't be applied to the inner layer out of the box. To manage this, we could pass separate props likeinnerLayerStyles
andouterLayerStyles
. However, this approach might affect other components usingSurface
, making it a more complex solution.2. Setting
borderWidth:1
for both modes and within theflat
mode setting theborderColor
totransparent
(implemented here)IMO this is the least impactful solution. It ensures both modes have matching dimensions (width and height) and restricts the change to the
Chip
component itself.Related issue
#4457
Test plan
You can test it by changing
ChipExample.tsx