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": "CommandBar changed the title attribute to render as tooltip and added readonly state (visitable by keyboard, functionally disabled)",
"type": "minor"
}
],
"packageName": "office-ui-fabric-react",
"email": "peterdunlop2519@gmail.com"
}
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,15 @@ $SearchBox-sidePadding: 8px; // padding in input on left and right sides without
&.itemLinkIsExpanded:hover {
background-color: $ms-color-neutralQuaternary;
}

&.inactive {
color: $ms-color-neutralTertiaryAlt;
cursor: default;
pointer-events: none;
.itemIcon {
color: $ms-color-neutralTertiaryAlt;
}
}
}

.itemIcon {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -188,8 +188,16 @@ export class CommandBar extends BaseComponent<ICommandBarProps, ICommandBarState
const className = css(
isLink ? ('ms-CommandBarItem-link ' + styles.itemLink) : ('ms-CommandBarItem-text ' + styles.itemText),
!item.name && ('ms-CommandBarItem--noName ' + styles.itemLinkIsNoName),
(expandedMenuItemKey === item.key) && ('is-expanded ' + styles.itemLinkIsExpanded)
(expandedMenuItemKey === item.key) && ('is-expanded ' + styles.itemLinkIsExpanded),
item.inactive ? styles.inactive : ''
);

let tooltipContent = '';

if (item.title) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Doesn't this add a tooltip to every command bar item? Is that intended?

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.

@micahgodbolt only if they provide a title attribute

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

ah title attribute, yup. gotcha. was thinking title was the text in the button.

tooltipContent = item.title;
}

const hasIcon = !!item.icon || !!item.iconProps;
const isNameVisible = !!item.name && !item.iconOnly;
const ariaLabel = item.ariaLabel || (item.iconOnly ? item.name : undefined);
Expand All @@ -201,6 +209,8 @@ export class CommandBar extends BaseComponent<ICommandBarProps, ICommandBarState
{ ...getNativeProps(item, buttonProperties) }
id={ this._id + item.key }
className={ className }
title={''}
aria-disabled={item.inactive}
onClick={ this._onItemClick(item) }
data-command-key={ itemKey }
aria-haspopup={ hasSubmenu(item) }
Expand Down Expand Up @@ -230,6 +240,8 @@ export class CommandBar extends BaseComponent<ICommandBarProps, ICommandBarState
{ ...getNativeProps(item, anchorProperties.concat(['disabled'])) }
id={ this._id + item.key }
className={ className }
title={''}
aria-disabled={item.inactive}
href={ item.disabled ? undefined : item.href }
data-command-key={ itemKey }
aria-haspopup={ hasSubmenu(item) }
Expand All @@ -255,6 +267,8 @@ export class CommandBar extends BaseComponent<ICommandBarProps, ICommandBarState
{ ...getNativeProps(item, divProperties.concat(['disabled'])) }
id={ this._id + item.key }
className={ className }
title={''}
aria-disabled={item.inactive}
data-command-key={ itemKey }
aria-haspopup={ hasSubmenu(item) }
aria-label={ ariaLabel }
Expand All @@ -281,6 +295,12 @@ export class CommandBar extends BaseComponent<ICommandBarProps, ICommandBarState
{ command }
</TooltipHost>
);
} else if (tooltipContent) {
command = (
<TooltipHost content={ tooltipContent }>
{ command }
</TooltipHost>
);
}

return (
Expand Down Expand Up @@ -399,6 +419,10 @@ export class CommandBar extends BaseComponent<ICommandBarProps, ICommandBarState

private _onItemClick(item: IContextualMenuItem): (ev: React.MouseEvent<HTMLButtonElement>) => void {
return (ev: React.MouseEvent<HTMLButtonElement>): void => {
if (item.inactive) {
return;
}

if (item.key === this.state.expandedMenuItemKey || !hasSubmenu(item)) {
this._onContextMenuDismiss();
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ exports[`CommandBar renders CommandBar correctly 1`] = `
className="ms-CommandBarItem"
>
<button
aria-disabled={undefined}
aria-expanded={false}
aria-haspopup={true}
aria-label={undefined}
Expand All @@ -32,6 +33,7 @@ exports[`CommandBar renders CommandBar correctly 1`] = `
name="TestText 1"
onClick={[Function]}
role="menuitem"
title=""
>
<span
className="ms-CommandBarItem-commandText"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -439,6 +439,12 @@ export interface IContextualMenuItem {
* Any additional properties to use when custom rendering menu items.
*/
[propertyName: string]: any;

/**
* Optional prop to make an item readonly which is disabled but visitable by keyboard, will apply aria-readonly and some styling. Not supported by all components
*/
inactive?: boolean;

}

export interface IContextualMenuSection extends React.Props<ContextualMenu> {
Expand Down