Merge pull request #7691 from diegobenetti/issue7671-take-ownership-button

Implements tooltip and label to the button to take over the captions
This commit is contained in:
Anton Georgiev 2019-07-04 15:07:08 -04:00 committed by GitHub
commit 14162aef96
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 17 additions and 26 deletions

View File

@ -84,6 +84,7 @@ const defaultProps = {
block: false, block: false,
iconRight: false, iconRight: false,
hideLabel: false, hideLabel: false,
tooltipLabel: '',
}; };
export default class Button extends BaseButton { export default class Button extends BaseButton {
@ -116,17 +117,17 @@ export default class Button extends BaseButton {
'aria-label': ariaLabel, 'aria-label': ariaLabel,
'aria-expanded': ariaExpanded, 'aria-expanded': ariaExpanded,
tooltipDistance, tooltipDistance,
tooltipLabel,
} = this.props; } = this.props;
const renderFuncName = circle ? 'renderCircle' : 'renderDefault'; const renderFuncName = circle ? 'renderCircle' : 'renderDefault';
if (hideLabel && !ariaExpanded) { if ((hideLabel && !ariaExpanded) || tooltipLabel) {
const tooltipLabel = label || ariaLabel; const buttonLabel = label || ariaLabel;
return ( return (
<Tooltip <Tooltip
tooltipDistance={tooltipDistance} tooltipDistance={tooltipDistance}
title={tooltipLabel} title={tooltipLabel || buttonLabel}
> >
{this[renderFuncName]()} {this[renderFuncName]()}
</Tooltip> </Tooltip>
@ -153,6 +154,7 @@ export default class Button extends BaseButton {
delete remainingProps.block; delete remainingProps.block;
delete remainingProps.hideLabel; delete remainingProps.hideLabel;
delete remainingProps.tooltipDistance; delete remainingProps.tooltipDistance;
delete remainingProps.tooltipLabel;
/* TODO: We can change this and make the button with flexbox to avoid html /* TODO: We can change this and make the button with flexbox to avoid html
changes */ changes */
@ -186,6 +188,7 @@ export default class Button extends BaseButton {
delete remainingProps.block; delete remainingProps.block;
delete remainingProps.hideLabel; delete remainingProps.hideLabel;
delete remainingProps.tooltipDistance; delete remainingProps.tooltipDistance;
delete remainingProps.tooltipLabel;
return ( return (
<BaseButton <BaseButton

View File

@ -22,6 +22,10 @@ const intlMessages = defineMessages({
id: 'app.captions.pad.ownership', id: 'app.captions.pad.ownership',
description: 'Label for taking ownership of closed captions pad', description: 'Label for taking ownership of closed captions pad',
}, },
takeOwnershipTooltip: {
id: 'app.captions.pad.ownershipTooltip',
description: 'Text for button for taking ownership of closed captions pad',
},
interimResult: { interimResult: {
id: 'app.captions.pad.interimResult', id: 'app.captions.pad.interimResult',
description: 'Title for speech recognition interim results', description: 'Title for speech recognition interim results',
@ -221,11 +225,8 @@ class Pad extends PureComponent {
{CaptionsService.canIOwnThisPad(ownerId) {CaptionsService.canIOwnThisPad(ownerId)
? ( ? (
<Button <Button
icon="pen_tool" color="primary"
size="sm" tooltipLabel={intl.formatMessage(intlMessages.takeOwnershipTooltip, { 0: name })}
ghost
color="dark"
hideLabel
onClick={() => { CaptionsService.takeOwnership(locale); }} onClick={() => { CaptionsService.takeOwnership(locale); }}
aria-label={intl.formatMessage(intlMessages.takeOwnership)} aria-label={intl.formatMessage(intlMessages.takeOwnership)}
label={intl.formatMessage(intlMessages.takeOwnership)} label={intl.formatMessage(intlMessages.takeOwnership)}

View File

@ -31,20 +31,6 @@ class Tooltip extends Component {
const expandedEl = tooltipTarget.parentElement.querySelector('[aria-expanded="true"]'); const expandedEl = tooltipTarget.parentElement.querySelector('[aria-expanded="true"]');
const isTarget = expandedEl === tooltipTarget; const isTarget = expandedEl === tooltipTarget;
if (expandedEl && !isTarget) return; if (expandedEl && !isTarget) return;
const findLabel = (node) => {
let rtn;
if (node) {
const { nodeName, lastChild, parentElement } = node;
if (nodeName.toLowerCase() === 'button') rtn = lastChild.innerText;
else rtn = findLabel(parentElement);
}
return rtn;
};
const label = findLabel(tooltipTarget);
if (label) tip.set({ content: label });
// if we are not able to get the text, the default content is used
tip.show(); tip.show();
} }

View File

@ -37,10 +37,11 @@
"app.captions.menu.cancelLabel": "Cancel", "app.captions.menu.cancelLabel": "Cancel",
"app.captions.pad.hide": "Hide closed captions", "app.captions.pad.hide": "Hide closed captions",
"app.captions.pad.tip": "Press Esc to focus editor toolbar", "app.captions.pad.tip": "Press Esc to focus editor toolbar",
"app.captions.pad.ownership": "Take ownership", "app.captions.pad.ownership": "Take over",
"app.captions.pad.ownershipTooltip": "You will be assigned as the owner of {0} captions",
"app.captions.pad.interimResult": "Interim results", "app.captions.pad.interimResult": "Interim results",
"app.captions.pad.dictationStart": "Start Dictation", "app.captions.pad.dictationStart": "Start dictation",
"app.captions.pad.dictationStop": "Stop Dictation", "app.captions.pad.dictationStop": "Stop dictation",
"app.captions.pad.dictationOnDesc": "Turns speech recognition on", "app.captions.pad.dictationOnDesc": "Turns speech recognition on",
"app.captions.pad.dictationOffDesc": "Turns speech recognition off", "app.captions.pad.dictationOffDesc": "Turns speech recognition off",
"app.note.title": "Shared Notes", "app.note.title": "Shared Notes",