Skip to content

Commit

Permalink
Fix: Enable focus to remain on copy button when clicked (#1379)
Browse files Browse the repository at this point in the history
* add focus function to copy buttons

* remove closing dialog function
  • Loading branch information
ElinorW authored Jan 26, 2022
1 parent 966b99c commit 319d354
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
9 changes: 7 additions & 2 deletions src/app/views/common/copy/CopyButton.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { IconButton, IIconProps, PrimaryButton } from '@fluentui/react';
import { IButton, IconButton, IIconProps, PrimaryButton } from '@fluentui/react';
import React, { useState } from 'react';
import { translateMessage } from '../../../utils/translate-messages';

Expand All @@ -18,10 +18,14 @@ export function CopyButton(props:ICopyButtonProps) {

const copyLabel: string = !copied ? translateMessage('Copy') : translateMessage('Copied');

const copyRef = React.createRef<IButton>();
const onSetFocus = () => copyRef.current!.focus();

const handleCopyClick = async () => {
props.handleOnClick(props);
setCopied(true);
handleTimeout();
onSetFocus();
};

const handleTimeout = () => {
Expand All @@ -40,9 +44,10 @@ export function CopyButton(props:ICopyButtonProps) {
ariaLabel={copyLabel}
style={props.style}
className={props.className}
componentRef={copyRef}
/>
:
<PrimaryButton onClick={handleCopyClick} text={copyLabel}/>
<PrimaryButton onClick={handleCopyClick} text={copyLabel} componentRef={copyRef}/>
}
</>
)
Expand Down
3 changes: 1 addition & 2 deletions src/app/views/query-response/QueryResponse.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ const QueryResponse = (props: IQueryResponseProps) => {
};

const handleCopy = () => {
copy('share-query-text').then(() => toggleShareQueryDialogState());
copy('share-query-text');
trackCopyEvent();
};

Expand Down Expand Up @@ -190,7 +190,6 @@ const QueryResponse = (props: IQueryResponseProps) => {
width: '100%',
height: 63,
overflowY: 'scroll',
border: 'none',
resize: 'none',
color: 'black'
}}
Expand Down

0 comments on commit 319d354

Please sign in to comment.