-
Notifications
You must be signed in to change notification settings - Fork 20
fix(MainNavigationBar): allow right slot to expand #1546
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
base: master
Are you sure you want to change the base?
Changes from 10 commits
558f9f0
83de53e
a31e7a9
e2855d0
fde438a
0448ee9
3fe8a3b
05ae75b
b0ad52f
f7a9b3f
44ef4b7
f84717e
698fa4b
dab18bb
c0b9c88
06bd1c4
327e2ca
6c254fe
1249a1e
c8b3750
08379e9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
|
Contributor
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. I dont feel really easy in terms of devExp to have another component called InlineItem to manage this kind of things Is not there any other solution? maybe manage this property in the wdyt @atabel ?
Contributor
Author
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. Good point, thanks! I’ve removed the public InlineItem component and moved the behavior into Inline via a growItems prop |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -79,6 +79,23 @@ type Props = { | |
| fullWidth?: boolean; | ||
| dataAttributes?: DataAttributes; | ||
| wrap?: boolean; | ||
| growItems?: number | ReadonlyArray<number>; | ||
| }; | ||
|
Comment on lines
70
to
+90
|
||
|
|
||
| const getChildKey = (child: React.ReactNode, index: number): React.Key => { | ||
| if (!React.isValidElement(child)) { | ||
| return index; | ||
| } | ||
|
|
||
| return child.key !== null && child.key !== undefined ? child.key : index; | ||
| }; | ||
|
|
||
| const shouldGrowItem = (growItems: Props['growItems'], index: number): boolean => { | ||
| if (growItems === undefined) { | ||
| return false; | ||
| } | ||
|
|
||
| return Array.isArray(growItems) ? growItems.includes(index) : growItems === index; | ||
| }; | ||
|
|
||
| const Inline = ({ | ||
|
|
@@ -93,28 +110,39 @@ const Inline = ({ | |
| fullWidth, | ||
| wrap, | ||
| dataAttributes, | ||
| growItems, | ||
| }: Props): JSX.Element => { | ||
| const {platformOverrides} = useTheme(); | ||
| const isStringSpace = typeof space === 'string'; | ||
| const childrenArray = React.Children.toArray(children).filter((child) => !!child || child === 0); | ||
|
Contributor
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. |
||
|
|
||
| const hasGrowItem = fullWidth && childrenArray.some((_, index) => shouldGrowItem(growItems, index)); | ||
|
|
||
| return ( | ||
| <div | ||
| className={classnames( | ||
| className, | ||
| styles.inline, | ||
| wrap ? styles.wrap : fullWidth ? styles.fullWidth : styles.noFullWidth, | ||
| isStringSpace ? (wrap ? styles.stringSpaceWithWrap : styles.stringSpace) : styles.marginInline | ||
| isStringSpace | ||
| ? wrap | ||
| ? styles.stringSpaceWithWrap | ||
| : styles.stringSpace | ||
| : styles.marginInline, | ||
| hasGrowItem && styles.flexLayout | ||
| )} | ||
|
Comment on lines
123
to
132
|
||
| style={{...applyCssVars(calcInlineVars(space, verticalSpace)), alignItems}} | ||
| role={role} | ||
| aria-label={ariaLabel} | ||
| aria-labelledby={ariaLabel ? undefined : ariaLabelledBy} | ||
| {...getPrefixedDataAttributes(dataAttributes, 'Inline')} | ||
| > | ||
| {React.Children.map(children, (child) => | ||
| !!child || child === 0 ? ( | ||
| {childrenArray.map((child, index) => { | ||
| return ( | ||
| <div | ||
| key={getChildKey(child, index)} | ||
|
Contributor
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. |
||
| role={role === 'list' ? 'listitem' : undefined} | ||
| className={classnames(shouldGrowItem(growItems, index) && styles.growItem)} | ||
|
|
||
| style={{ | ||
| // Hack to fix https://jira.tid.es/browse/WEB-1683 | ||
| // In iOS the inline component sometimes cuts the last line of the content | ||
|
|
@@ -126,8 +154,8 @@ const Inline = ({ | |
| > | ||
| {child} | ||
| </div> | ||
| ) : null | ||
| )} | ||
| ); | ||
| })} | ||
| </div> | ||
| ); | ||
| }; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -313,9 +313,16 @@ export const navigationBarContentRightExpanded = style([ | |
| }), | ||
| { | ||
| paddingLeft: 136, | ||
| minWidth: 0, | ||
| width: 0, | ||
| }, | ||
| ]); | ||
|
|
||
| export const navigationBarContentRightExpandedContent = style({ | ||
| width: '100%', | ||
|
Contributor
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. What about an
Contributor
Author
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. like this? |
||
| minWidth: 0, | ||
| }); | ||
|
|
||
| const spacerMobile = style({ | ||
| '@media': { | ||
| [mq.tabletOrSmaller]: { | ||
|
|
||


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.
why the minWidth?
Uh oh!
There was an error while loading. Please reload this page.
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.
minWidth: 0was intentional here. In a flex layout, flex items havemin-width: autoby default, so an expanded item can refuse to shrink below its content size and push adjacent items out of the available space. SettingminWidth: 0allows the expanded item to shrink properly and lets inner components handle truncation/overflow... But i haven't been able to prove this case in a playroom, should I delete the minWidth then?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.
Hmm I don't know if that behaviour is desirable, perhaps we could live without it for the moment...
https://developer.mozilla.org/en-US/play?id=pEK8gpiRaKCWYKNxPpXPkgOoAEQy8NkIAdjrAPjKL0gP%2BAzWTL%2FLoG9rA2WXLAksvUN8leTXOzoc46Dg