Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 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;
}

&.readOnly {
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.readOnly ? styles.readOnly : ""
);

var tooltipContent: string = "";

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.readOnly}
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.readOnly}
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.readOnly}
data-command-key={ itemKey }
aria-haspopup={ hasSubmenu(item) }
aria-label={ ariaLabel }
Expand Down Expand Up @@ -282,6 +296,13 @@ export class CommandBar extends BaseComponent<ICommandBarProps, ICommandBarState
</TooltipHost>
);
}
else if (tooltipContent) {

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.

Nit: this should be on the same line as the closing {

command = (
<TooltipHost content={ tooltipContent }>
{ command }
</TooltipHost>
);
}

return (
<div className={ css('ms-CommandBarItem', styles.item, item.className) } key={ itemKey } ref={ itemKey }>
Expand Down Expand Up @@ -399,6 +420,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.readOnly) {

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.

If this is added to command bar, it should also be added to the contextualmenu click handler.

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.

@joschect I added a comment on this prop that it's implementation is not supported by all components, like for contextualmenu and for button as micah as mentioned, then other teams can come in and add the functionality on these components as they need them. is that ok?

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 @@ -439,6 +439,11 @@ 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
*/
readOnly?: string;
}

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