-
Notifications
You must be signed in to change notification settings - Fork 2.9k
transitioning title attribute to render as tooltip, and adding readon… #4261
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 6 commits
d528f82
dfdb492
c21772d
2ea1c59
926de19
4946fce
a69f46b
3fa3601
bc086a0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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 |
|---|---|---|
|
|
@@ -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) { | ||
| tooltipContent = item.title; | ||
| } | ||
|
|
||
| const hasIcon = !!item.icon || !!item.iconProps; | ||
| const isNameVisible = !!item.name && !item.iconOnly; | ||
| const ariaLabel = item.ariaLabel || (item.iconOnly ? item.name : undefined); | ||
|
|
@@ -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) } | ||
|
|
@@ -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) } | ||
|
|
@@ -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 } | ||
|
|
@@ -282,6 +296,13 @@ export class CommandBar extends BaseComponent<ICommandBarProps, ICommandBarState | |
| </TooltipHost> | ||
| ); | ||
| } | ||
| else if (tooltipContent) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 }> | ||
|
|
@@ -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) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 { | ||
|
|
||
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.