session-desktop/ts/components/session/SessionIdEditable.tsx

49 lines
1 KiB
TypeScript
Raw Normal View History

import React from 'react';
interface Props {
placeholder?: string;
text?: string;
editable?: boolean;
onChange?: any;
}
export class SessionIdEditable extends React.PureComponent<Props> {
2020-01-28 06:39:12 +01:00
private readonly inputRef: React.RefObject<HTMLInputElement>;
public constructor(props: Props) {
super(props);
this.inputRef = React.createRef();
}
public componentWillUnmount() {
//FIXME ugly hack to empty the content editable div used on enter session ID
window.Session.emptyContentEditableDivs();
}
2020-01-28 06:39:12 +01:00
public focus() {
if (this.inputRef.current) {
this.inputRef.current.focus();
}
}
public render() {
const { placeholder, editable, onChange, text } = this.props;
return (
<div
2020-01-28 06:39:12 +01:00
ref={this.inputRef}
className="session-id-editable"
placeholder={placeholder}
contentEditable={editable}
onInput={(e: any) => {
if (editable) {
onChange(e);
}
}}
>
{text}
</div>
);
}
}