Skip to content
Open
Show file tree
Hide file tree
Changes from 10 commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
558f9f0
Allow MainNavigationBar right prop to expand
AlexandraGallipoliRodrigues May 6, 2026
83de53e
Add InlineItem grow support to let children consume available space i…
AlexandraGallipoliRodrigues May 6, 2026
a31e7a9
preserve child keys in wrapped items
AlexandraGallipoliRodrigues May 6, 2026
e2855d0
added screenshot test
AlexandraGallipoliRodrigues May 6, 2026
fde438a
removed InlineItem component and moved the behavior into Inline via a…
AlexandraGallipoliRodrigues May 7, 2026
0448ee9
Merge branch 'master' of github.com:Telefonica/mistica-web into alex/…
AlexandraGallipoliRodrigues May 7, 2026
3fe8a3b
move flexLayout after spacing classes
AlexandraGallipoliRodrigues May 8, 2026
05ae75b
Merge branch 'master' of github.com:Telefonica/mistica-web into alex/…
AlexandraGallipoliRodrigues May 8, 2026
b0ad52f
WEB-2439: empty commit, link PR to ticket
AlexandraGallipoliRodrigues May 8, 2026
f7a9b3f
Merge branch 'master' into alex/OBVIVO-3456-fix-MainNavigationBar-all…
AlexandraGallipoliRodrigues May 8, 2026
44ef4b7
added growItem case at inline story
AlexandraGallipoliRodrigues May 11, 2026
f84717e
added inline screenshot test
AlexandraGallipoliRodrigues May 11, 2026
698fa4b
Guard grow item styles behind fullWidth and added comment
AlexandraGallipoliRodrigues May 11, 2026
dab18bb
Merge branch 'master' into alex/OBVIVO-3456-fix-MainNavigationBar-all…
AlexandraGallipoliRodrigues May 11, 2026
c0b9c88
PR changes: rename growItem for expand prop and undo changes at main-…
AlexandraGallipoliRodrigues May 12, 2026
06bd1c4
minor changes
AlexandraGallipoliRodrigues May 12, 2026
327e2ca
PR changes: use React.Children.map and deleted filter
AlexandraGallipoliRodrigues May 13, 2026
6c254fe
Potential fix for pull request finding
AlexandraGallipoliRodrigues May 13, 2026
1249a1e
filter out empty strings ('')
AlexandraGallipoliRodrigues May 13, 2026
c8b3750
Potential fix for pull request finding
AlexandraGallipoliRodrigues May 13, 2026
08379e9
deleted minWidth
AlexandraGallipoliRodrigues May 13, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
15 changes: 15 additions & 0 deletions src/__screenshot_tests__/navigation-bar-screenshot-test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -285,3 +285,18 @@ test.each(['large' /* 'small' */])('MainNavigationBar inverse with %s menu in DE
await page.click(startButton);
expect(await page.screenshot()).toMatchImageSnapshot({failureThreshold: 0.00002});
});

test('MainNavigationBar large with expanded right slot', async () => {
const page = await openStoryPage({
id: 'components-navigation-bars-mainnavigationbar--default',
device: 'DESKTOP',
args: {
large: true,
expandedRightSlot: true,
},
});

const image = await page.screenshot();

expect(image).toMatchImageSnapshot();
});
45 changes: 32 additions & 13 deletions src/__stories__/main-navigation-bar-story.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@ import {
Avatar,
Badge,
IconShoppingCartRegular,
Inline,
MainNavigationBar,
NavigationBarAction,
NavigationBarActionGroup,
Placeholder,
SearchField,
Stack,
Text3,
useScreenSize,
Expand Down Expand Up @@ -45,6 +47,7 @@ type Args = {
topSlotBackgroundColor: string;
wide: boolean;
paddingX: PadSize | 'undefined';
expandedRightSlot: boolean;
};

export const Default: StoryComponent<Args> = ({
Expand All @@ -60,10 +63,34 @@ export const Default: StoryComponent<Args> = ({
topSlotBackgroundColor,
wide,
paddingX,
expandedRightSlot,
}) => {
const [selectedIndex, setSelectedIndex] = React.useState(0);
const {isDesktopOrBigger} = useScreenSize();

const right = expandedRightSlot ? (
<Inline fullWidth space={16} alignItems="center" growItems={0}>
<SearchField fullWidth name="search" label="Search" />

<NavigationBarAction onPress={() => {}} aria-label="Entrar">
<Avatar src={avatarImg} size={isDesktopOrBigger ? 32 : 24} initials="ML" />
{isDesktopOrBigger && 'Entrar'}
</NavigationBarAction>
</Inline>
) : (
<NavigationBarActionGroup>
<NavigationBarAction onPress={() => {}} aria-label="shopping cart with 2 items">
<Badge value={2}>
<IconShoppingCartRegular color="currentColor" />
</Badge>
</NavigationBarAction>
<NavigationBarAction onPress={() => {}} aria-label="Open profile">
<Avatar src={avatarImg} size={isDesktopOrBigger ? 32 : 24} initials="ML" />
{isDesktopOrBigger && 'María López Serrano'}
</NavigationBarAction>
</NavigationBarActionGroup>
);

return (
<MainNavigationBar
variant={variant}
Expand Down Expand Up @@ -116,19 +143,7 @@ export const Default: StoryComponent<Args> = ({
: undefined
}
selectedIndex={selectedIndex}
right={
<NavigationBarActionGroup>
<NavigationBarAction onPress={() => {}} aria-label="shopping cart with 2 items">
<Badge value={2}>
<IconShoppingCartRegular color="currentColor" />
</Badge>
</NavigationBarAction>
<NavigationBarAction onPress={() => {}} aria-label="Open profile">
<Avatar src={avatarImg} size={isDesktopOrBigger ? 32 : 24} initials="ML" />
{isDesktopOrBigger && 'María López Serrano'}
</NavigationBarAction>
</NavigationBarActionGroup>
}
right={right}
wide={wide ? (paddingX === 'undefined' ? true : {paddingX}) : false}
/>
);
Expand All @@ -149,6 +164,7 @@ Default.args = {
topSlotBackgroundColor: '',
wide: false,
paddingX: 'undefined',
expandedRightSlot: false,
};

Default.argTypes = {
Expand All @@ -171,4 +187,7 @@ Default.argTypes = {
control: {type: 'select'},
if: {arg: 'wide'},
},
expandedRightSlot: {
control: {type: 'boolean'},
},
};
9 changes: 9 additions & 0 deletions src/inline.css.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,15 @@ export const stringSpaceWithWrap = style({
justifyContent: space,
});

export const flexLayout = style({
display: 'flex',
});

export const growItem = style({
flex: 1,
minWidth: 0,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why the minWidth?

Copy link
Copy Markdown
Contributor Author

@AlexandraGallipoliRodrigues AlexandraGallipoliRodrigues May 13, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

minWidth: 0 was intentional here. In a flex layout, flex items have min-width: auto by default, so an expanded item can refuse to shrink below its content size and push adjacent items out of the available space. Setting minWidth: 0 allows 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?

Copy link
Copy Markdown
Contributor

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

});

globalStyle(`${marginInline} > div`, {
marginLeft: space,
marginTop: fallbackVar(verticalSpace, space),
Expand Down
38 changes: 33 additions & 5 deletions src/inline.tsx
Copy link
Copy Markdown
Contributor

@yceballost yceballost May 6, 2026

Choose a reason for hiding this comment

The 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 <Inline> component?

wdyt @atabel ?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The 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
Expand Up @@ -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 = ({
Expand All @@ -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);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

According to the doc react filters empty elements:

Image


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)}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would use React.Children.map because key logic is handled automatically:

Image

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
Expand All @@ -126,8 +154,8 @@ const Inline = ({
>
{child}
</div>
) : null
)}
);
})}
</div>
);
};
Expand Down
7 changes: 7 additions & 0 deletions src/navigation-bar.css.ts
Original file line number Diff line number Diff line change
Expand Up @@ -313,9 +313,16 @@ export const navigationBarContentRightExpanded = style([
}),
{
paddingLeft: 136,
minWidth: 0,
width: 0,
},
]);

export const navigationBarContentRightExpandedContent = style({
width: '100%',
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about an expand prop on the Inline element? It would set its width to 100% whenever it is set. This way we wouldn't have to modify navigation bar I think. This prop could accept what you currently have in flexGrow prop and wouldn't need fullWidth to be set.

Copy link
Copy Markdown
Contributor Author

@AlexandraGallipoliRodrigues AlexandraGallipoliRodrigues May 12, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

like this?

minWidth: 0,
});

const spacerMobile = style({
'@media': {
[mq.tabletOrSmaller]: {
Expand Down
8 changes: 7 additions & 1 deletion src/navigation-bar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,8 @@ type NavigationBarContentContainerProps = {

const NavigationBarContentContainer = React.forwardRef<HTMLDivElement, NavigationBarContentContainerProps>(
({right, children, desktopOnly, expandRightContent}, ref) => {
const shouldWrapRightContent =
expandRightContent && React.isValidElement<{fullWidth?: boolean}>(right) && right.props.fullWidth;
return (
<div
ref={ref}
Expand All @@ -129,7 +131,11 @@ const NavigationBarContentContainer = React.forwardRef<HTMLDivElement, Navigatio
: styles.navigationBarContentRight
}
>
{right}
{shouldWrapRightContent ? (
<div className={styles.navigationBarContentRightExpandedContent}>{right}</div>
) : (
right
)}
</div>
)}
</div>
Expand Down
Loading