Skip to content

Commit

Permalink
chore: re-render copybutton after textfield ref is mounted #2025
Browse files Browse the repository at this point in the history
  • Loading branch information
marek-mihok committed Aug 17, 2023
1 parent fff09ab commit 825e26d
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions ui/src/copyable_text.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,7 @@ export const ClipboardCopyButton = ({ value, anchorElement, showOnHoverOnly = fa
setVisible(false)
})
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [value])
}, [value, anchorElement])

React.useEffect(() => () => window.clearTimeout(timeoutRef.current), [])

Expand All @@ -110,14 +109,16 @@ export const XCopyableText = ({ model }: { model: CopyableText }) => {
const
{ name, multiline, label, value, height } = model,
heightStyle = multiline && height === '1' ? fullHeightStyle : undefined,
ref = React.useRef<Fluent.ITextField>(null),
domRef = React.useRef<HTMLDivElement>(null)
[inputEl, setInputEl] = React.useState(),
domRef = React.useCallback(node => {
const inputEl = node?.children[0]?.children[1]
if (inputEl) setInputEl(inputEl)
}, [])

return (
<>
<Fluent.TextField
data-test={name}
componentRef={ref}
// Temporary solution which will be replaced with ref once TextField is converted to a function component.
elementRef={domRef}
value={value}
Expand All @@ -135,8 +136,7 @@ export const XCopyableText = ({ model }: { model: CopyableText }) => {
readOnly
/>
<ClipboardCopyButton
// Use text input as anchorElement.
anchorElement={domRef.current?.children[0]?.children[1]}
anchorElement={inputEl}
showOnHoverOnly={!!multiline} value={value}
/>
</>
Expand Down

0 comments on commit 825e26d

Please sign in to comment.