Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"changes": [
{
"packageName": "office-ui-fabric-react",
"comment": "Updated contextual menu to pass the correct number",
"type": "patch"
}
],
"packageName": "office-ui-fabric-react",
"email": "chiechan@microsoft.com"
}
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,8 @@ export class ContextualMenu extends BaseComponent<IContextualMenuProps, IContext
for (let item of items) {
if (item.itemType !== ContextualMenuItemType.Divider &&
item.itemType !== ContextualMenuItemType.Header) {
totalItemCount++;
const itemCount = item.customOnRenderListLength ? item.customOnRenderListLength : 1;
totalItemCount += itemCount;
}
}
return (
Expand Down Expand Up @@ -313,11 +314,13 @@ export class ContextualMenu extends BaseComponent<IContextualMenuProps, IContext
onKeyDown={ this._onKeyDown }
>
{ items.map((item, index) => {
if (item.itemType === ContextualMenuItemType.Divider ||
item.itemType === ContextualMenuItemType.Header) {
indexCorrection++;
const menuItem = this._renderMenuItem(item, index, indexCorrection, totalItemCount, hasCheckmarks, hasIcons);
if (item.itemType !== ContextualMenuItemType.Divider &&
item.itemType !== ContextualMenuItemType.Header) {
const indexIncrease = item.customOnRenderListLength ? item.customOnRenderListLength : 1;
indexCorrection += indexIncrease;
}
return this._renderMenuItem(item, index, index - indexCorrection, totalItemCount, hasCheckmarks, hasIcons);
return menuItem;
}) }
</ul>
</FocusZone>
Expand Down Expand Up @@ -444,7 +447,7 @@ export class ContextualMenu extends BaseComponent<IContextualMenuProps, IContext

private _renderNormalItem(item: IContextualMenuItem, classNames: IMenuItemClassNames, index: number, focusableElementIndex: number, totalItemCount: number, hasCheckmarks: boolean, hasIcons: boolean): React.ReactNode {
if (item.onRender) {
return [item.onRender({ 'aria-posinset': focusableElementIndex, 'aria-setsize': totalItemCount, ...item }, this.dismiss)];
return [item.onRender({ 'aria-posinset': focusableElementIndex + 1, 'aria-setsize': totalItemCount, ...item }, this.dismiss)];
}
if (item.href) {
return this._renderAnchorMenuItem(item, classNames, index, focusableElementIndex, totalItemCount, hasCheckmarks, hasIcons);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -406,6 +406,13 @@ export interface IContextualMenuItem {
*/
role?: string;

/**
* When rendering a custom component that is passed in, the component might also be a list of
* elements. We want to keep track of the correct index our menu is using based off of
* the length of the custom list. It is up to the user to increment the count for their list.
*/
customOnRenderListLength?: number;

/**
* Any additional properties to use when custom rendering menu items.
*/
Expand Down