fix: fixed Chip "shadow" and height issue
#4461
Merged
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
Chipcomponent when aChipwithmode="outlined"is used next to one withmode="flat"(see screenshot). TheChipwithmode="flat"displays a kind of "shadow" at the bottom.This problem is caused by the
Surfacecomponent, which splits styles provided via props intoouterLayerViewStylesandinnerLayerViewStyles. Specifically, it is caused by thebackgroundColor, which has the same value in bothouterLayerViewStylesandinnerLayerViewStyles(see below, reference):A
Chipwithmode="outlined"is2dplarger in width and height than one withmode="flat"due to itsborderWidthof1dp. When both modes are placed next to each other, the outerViewof theSurfacecomponent adjusts to fill the height difference, but the innerViewdoes not. Since the background color for a disabledChipuses 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: 1to theSurfaceused insideChipcomponentAdding
flexGrow: 1would resolve the issue by allowing the innerViewof theSurfaceto 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 likeinnerLayerStylesandouterLayerStyles. However, this approach might affect other components usingSurface, making it a more complex solution.2. Setting
borderWidth:1for both modes and within theflatmode setting theborderColortotransparent(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
Chipcomponent itself.Related issue
#4457
Test plan
You can test it by changing
ChipExample.tsx