CommandBar: Scrollbar appears for child items
Issue: Implement a command bar and add more than one child item to a top level item. Click the top level item and observe a scrollbar next to the child items.
Expected behavior: Implement a command bar and add more than one child item to a top level item. Click the top level item and observe no scrollbar next to the child items.
Code to replicate issue:
.commandBar i{
display: none;
}
const commandBarItems = this._generateCommandBarItems();
public render(): JSX.Element {
return (
<div className={styles.opportunityTracker}>
<div className={styles.container}>
{/* filter bar */}
<div className="ms-Grid-row">
<div className={css("ms-Grid-col ms-u-sm12", styles.commandBar)}>
<CommandBar
isSearchBoxVisible={ false }
searchPlaceholderText='Search...'
elipisisAriaLabel='More options'
items={ this.state["commandBarItems"] }
/>
</div>
</div>
private _generateCommandBarItems(): Array{
const contextualMenuItems: Array = [];
//Sort
contextualMenuItems.push({
key: 'Sort',
name: 'Sort',
icon: 'sortLines',
onClick: (item: IContextualMenuItem, ev: React.MouseEvent) : void => {ev.preventDefault();},
items: [
{
key: 'ALPHABETICAL',
name: 'ALPHABETICAL',
onClick: (item: IContextualMenuItem, ev: React.MouseEvent) : void => {
this.setState({
//replace setting the state with react add-ons update
//npm i react-addons-update
//let update = require{'react-addons-update'};
opportunities: this._sortAndFilterOpportunities(item.key, this.state["statusSelectedKey"], this.state["ownerSelectedKey"]),
sortedBySelectedKey: item.key
});
ev.preventDefault();
}
},
{
key: 'FORECAST DATE',
name: 'FORECAST DATE',
onClick: (item: IContextualMenuItem, ev: React.MouseEvent) : void => {
this.setState({
opportunities: this._sortAndFilterOpportunities(item.key, this.state["statusSelectedKey"], this.state["ownerSelectedKey"]),
sortedBySelectedKey: item.key
});
ev.preventDefault();
},
isChecked: true
}
]
});
@joschect can you take a look here
@dzearing this should be resolved with the changing of padding to margin which I just put in yesterday and I think is in 56.1. @TBag could you update to the latest version and try again?
Thanks, @joschect
It looks like 56.1 introduced some breaking changes for IContextualMenuItem. Once I get it sorted out I'll let you know if this fixed the scroll bar issue.
[14:45:58] Error - typescript - src\webparts\opportunityTracker\components\OpportunityTracker.tsx(118,30): error TS2345: Argument of type '{ [x: string]: string | ((item: IContextualMenuItem, ev: MouseEvent) => void) | ({ [x: string]: s...' is not assignable to parameter of type 'IContextualMenuItem'.
@TBag What version were you using before? In 53 there was a breaking change introduced that changed the onclick parameter order. https://github.com/OfficeDev/office-ui-fabric-react/releases/tag/v0.53.0
@joschect We were using 0.36.0. Thanks for sending me the link to the release notes. This is a simple fix and I'm going to test it now.
@joschect The scrollbar still appears and a new issue now occurs. When I click the top level item the command bar the page refreshes. I need to sort out the code on our end to determine what else has changed and how we need to handle the click event for the top level item so it doesn't refresh the page, and instead allows us to select the child items.
@TBag When you click the top level item in the contextual menu or in the command bar?
In regards to the scroll bar, are you adding any css or rendering custom items?
@joschect Top level item in the command bar. The items we are rendering can be seen in the code sample above. Is that what you consider a custom item? We are not adding any CSS to them except for the style that we used to fix the empty box from appearing. That style is shown in the code sample above as well. If you would like to pair on this or would like the source code let me know.
@TBag I missed the code sample! My bad. That should be good enough, I'll take a look.
@TBag I'm unable to replicate this problem. I'll keep investigating.
@joschect Hmm, maybe I should send you the code sample. Are you testing in Google Chrome? Issue #375 describes the empty box.
@TBag Yeah I'm using chrome. I don't think you need to send me the code sample just yet. Have you guys upgraded to the lastest styles? You'll need to make sure that you upgrade your dependency to use office-ui-fabric-core 4.0.0 instead of office-ui-fabric 2.6.0.
Upgrading to 4.0.0.0 eliminated the scroll bars! The issue where clicking the top level item in the command bar causes the page to refresh still occurs. Should we close this issue and open a new one for that?
Good to hear! I think you should probably open a different issue for the page refresh as that sounds to be unrelated to the scrollbars!
@joschect Thanks again! Scrollbar issue is fixed. Closing Issue.
I will open a new issue for the refresh issue.