CopyableInput: oh yeah, make the input actually copy
This commit is contained in:
parent
48ba485a0d
commit
82aad21900
1 changed files with 7 additions and 1 deletions
|
@ -5,7 +5,7 @@ import { Button, HStack, Input } from './ui';
|
||||||
|
|
||||||
interface ICopyableInput {
|
interface ICopyableInput {
|
||||||
/** Text to be copied. */
|
/** Text to be copied. */
|
||||||
value?: string,
|
value: string,
|
||||||
}
|
}
|
||||||
|
|
||||||
/** An input with copy abilities. */
|
/** An input with copy abilities. */
|
||||||
|
@ -14,6 +14,12 @@ const CopyableInput: React.FC<ICopyableInput> = ({ value }) => {
|
||||||
|
|
||||||
const selectInput = () => {
|
const selectInput = () => {
|
||||||
input.current?.select();
|
input.current?.select();
|
||||||
|
|
||||||
|
if (navigator.clipboard) {
|
||||||
|
navigator.clipboard.writeText(value);
|
||||||
|
} else {
|
||||||
|
document.execCommand('copy');
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|
Loading…
Reference in a new issue