Skip to content

Commit

Permalink
feat(ClipboardCopy): added event to onChange prop (#8747)
Browse files Browse the repository at this point in the history
* feat(ClipboardCopy): added event to onChange prop

* feat(ClipboardCopyExpanded): changed onChange param order
  • Loading branch information
wise-king-sullyman committed Mar 1, 2023
1 parent 0a87f55 commit ed13078
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ export interface ClipboardCopyProps extends Omit<React.HTMLProps<HTMLDivElement>
/** A function that is triggered on clicking the copy button. */
onCopy?: (event: React.ClipboardEvent<HTMLDivElement>, text?: React.ReactNode) => void;
/** A function that is triggered on changing the text. */
onChange?: (text?: string | number) => void;
onChange?: (event: React.FormEvent, text?: string | number) => void;
/** The text which is copied. */
children: React.ReactNode;
/** Additional actions for inline clipboard copy. Should be wrapped with ClipboardCopyAction. */
Expand Down Expand Up @@ -119,7 +119,7 @@ export class ClipboardCopy extends React.Component<ClipboardCopyProps, Clipboard
// eslint-disable-next-line @typescript-eslint/no-unused-vars
componentDidUpdate = (prevProps: ClipboardCopyProps, prevState: ClipboardCopyState) => {
if (prevProps.children !== this.props.children) {
this.updateText(this.props.children as string | number);
this.setState({ text: this.props.children as string | number });
}
};

Expand All @@ -136,9 +136,9 @@ export class ClipboardCopy extends React.Component<ClipboardCopyProps, Clipboard
}));
};

updateText = (text: string | number) => {
updateText = (text: string | number, event: React.FormEvent) => {
this.setState({ text });
this.props.onChange(text);
this.props.onChange(event, text);
};

render = () => {
Expand Down Expand Up @@ -265,7 +265,7 @@ export class ClipboardCopy extends React.Component<ClipboardCopyProps, Clipboard
isReadOnly={isReadOnly}
isCode={isCode}
id={`content-${id}`}
onChange={this.updateText}
onChange={(event, text) => this.updateText(text, event)}
>
{this.state.text}
</ClipboardCopyExpanded>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { PickOptional } from '../../helpers/typeUtils';
export interface ClipboardCopyExpandedProps extends Omit<ClipboardCopyProps, 'onChange'> {
className?: string;
children: React.ReactNode;
onChange?: (text: string, e: React.FormEvent<HTMLDivElement>) => void;
onChange?: (e: React.FormEvent<HTMLDivElement>, text: string) => void;
isReadOnly?: boolean;
isCode?: boolean;
}
Expand All @@ -32,7 +32,7 @@ export class ClipboardCopyExpanded extends React.Component<ClipboardCopyExpanded
<div
suppressContentEditableWarning
className={css(styles.clipboardCopyExpandableContent, className)}
onInput={(e: any) => onChange(e.target.innerText, e)}
onInput={(e: any) => onChange(e, e.target.innerText)}
contentEditable={!isReadOnly}
{...props}
>
Expand Down

0 comments on commit ed13078

Please sign in to comment.