Command bar hide action labels when too small
Asked Answered
L

0

6

Expected behavior

Expected behavior

This is what I'm trying to achieve with the CommandBar.

When there's not enough space for the items label I want to hide the labels and not go in the overflow menu. When I resize the CommandBar I want the labels to reappear if there's enough space.

I'm able to hide the labels using the iconOnly props and the onReduceData callback.

Then I tried to use the onGrowData to restore the iconOnly when the commandBar is resized, but since there's no items in the overflow, the callback is never called.

Current behavior

enter image description here

Here is the simplify code:

<CommandBar
className='CommandBar'
items={[{
    iconProps: { iconName: 'Previous' },
    key: 'FindPrevious',
    onClick: () => { this.findPrevious() },
    text: 'Find Previous',
},
{
    iconProps: { iconName: 'Next' },
    key: 'FindNext',
    onClick: () => { this.findNext() },
    text: 'Find Next',
}]}
farItems={[{
    iconProps: { iconName: 'Search' },
    key: 'FindAll',
    onClick: this.findAll,
    text: 'Find All',
}]}

onReduceData={this.onReduceData}
/>

private onReduceData = (data: ICommandBarData): any => {
    data.primaryItems[0].iconOnly = true;
    data.primaryItems[1].iconOnly = true;
    return data;
}
Levator answered 30/1, 2019 at 21:32 Comment(1)
onGrow is never called if there aren't items in the overflow? That's definitely a bug if true! Can you get this into a codepen (aka.ms/fabricpen) and submit and issue to github.com/OfficeDev/office-ui-fabric-reactAirtoair

© 2022 - 2024 — McMap. All rights reserved.