-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
fix: expand interactive targets to the 48dp minimum #5080
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
Closed
Closed
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -169,6 +169,25 @@ export type Props = $Omit<React.ComponentProps<typeof Surface>, 'mode'> & { | |
| * export default MyComponent; | ||
| * ``` | ||
| */ | ||
| /** | ||
| * Room the chip reserves on its right for the close button, which fills all of | ||
| * it, so the body stops here and the two divide the chip. | ||
| * | ||
| * MD3 splits the same way and does not give a chip's trailing action 48dp; in | ||
| * material-web it is 24x24 with no expansion. This column is wider than that and | ||
| * gets no vertical expansion, so the strips above and below belong to the body | ||
| * and a near miss activates the chip rather than deleting it. | ||
| * @see https://github.com/material-components/material-web/blob/main/chips/internal/_trailing-icon.scss | ||
| */ | ||
| const CLOSE_AFFORDANCE_WIDTH = 34; | ||
|
|
||
| /** | ||
| * Floor for the clamp below. The glyph is 18dp and sits 8dp from the right, so | ||
| * under this it hangs over the chip body, and part of the visible icon would | ||
| * activate the chip instead of removing it. | ||
| */ | ||
| const CLOSE_AFFORDANCE_MIN_WIDTH = 26; | ||
|
|
||
|
Comment on lines
+172
to
+190
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These constants are added between the component and its JSDoc, which will break documentation generation for the component. |
||
| const Chip = ({ | ||
| mode = 'flat', | ||
| children, | ||
|
|
@@ -273,7 +292,7 @@ const Chip = ({ | |
| : 8 * multiplier, | ||
| }; | ||
| const contentSpacings = { | ||
| paddingRight: onClose ? 34 : 0, | ||
| paddingRight: onClose ? CLOSE_AFFORDANCE_WIDTH : 0, | ||
| }; | ||
| const labelTextStyle = { | ||
| color: textColor, | ||
|
|
@@ -399,8 +418,12 @@ const Chip = ({ | |
| disabled={disabled} | ||
| role="button" | ||
| aria-label={closeIconAccessibilityLabel} | ||
| style={styles.closeButton} | ||
| > | ||
| <View style={[styles.icon, styles.closeIcon, styles.md3CloseIcon]}> | ||
| <View | ||
| testID={`${testID}-close-icon`} | ||
| style={[styles.icon, styles.closeIcon, styles.md3CloseIcon]} | ||
| > | ||
| {closeIcon ? ( | ||
| <Icon source={closeIcon} color={iconColor} size={iconSize} /> | ||
| ) : ( | ||
|
|
@@ -451,6 +474,10 @@ const styles = StyleSheet.create({ | |
| md3CloseIcon: { | ||
| marginRight: 8, | ||
| padding: 0, | ||
| // `styles.icon` sets `alignSelf: 'center'`, which beats `alignItems` on the | ||
| // parent. Without this the glyph centres in the wider column and moves 4dp | ||
| // left. | ||
| alignSelf: 'flex-end', | ||
| }, | ||
| md3LabelText: { | ||
| textAlignVertical: 'center', | ||
|
|
@@ -481,9 +508,19 @@ const styles = StyleSheet.create({ | |
| closeButtonStyle: { | ||
| position: 'absolute', | ||
| right: 0, | ||
| width: CLOSE_AFFORDANCE_WIDTH, | ||
| // A chip narrower than this column would hand the whole thing to the close | ||
| // button. Never more than half, never less than the glyph needs; minWidth | ||
| // wins over maxWidth. | ||
| minWidth: CLOSE_AFFORDANCE_MIN_WIDTH, | ||
| maxWidth: '50%', | ||
| height: '100%', | ||
| }, | ||
| closeButton: { | ||
| width: '100%', | ||
| height: '100%', | ||
| // Vertical only. The glyph pins itself horizontally with `alignSelf`. | ||
| justifyContent: 'center', | ||
| alignItems: 'center', | ||
| }, | ||
| touchable: { | ||
| width: '100%', | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
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.
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.
what it used to is not relevant as a code comment