aboutsummaryrefslogtreecommitdiff
path: root/src/client/views/EditableView.tsx
diff options
context:
space:
mode:
authorusodhi <61431818+usodhi@users.noreply.github.com>2020-11-17 19:28:30 +0530
committerusodhi <61431818+usodhi@users.noreply.github.com>2020-11-17 19:28:30 +0530
commit86408e6d93fbe6501694371736fe74b81ed39cf3 (patch)
tree17b89a6209c66284f89e2636a8157435ce1045c0 /src/client/views/EditableView.tsx
parenta002e0e5c5910f78c8f3910ad4101386d30ebf70 (diff)
parent28dccafaa4aa446dd88c1b6f4218a0d7f79fa1bb (diff)
Merge branch 'master' of https://github.com/browngraphicslab/Dash-Web into acls_uv
Diffstat (limited to 'src/client/views/EditableView.tsx')
-rw-r--r--src/client/views/EditableView.tsx37
1 files changed, 27 insertions, 10 deletions
diff --git a/src/client/views/EditableView.tsx b/src/client/views/EditableView.tsx
index 8b1b12365..ed7a8265f 100644
--- a/src/client/views/EditableView.tsx
+++ b/src/client/views/EditableView.tsx
@@ -35,6 +35,7 @@ export interface EditableProps {
sizeToContent?: boolean;
maxHeight?: number;
display?: string;
+ overflow?: string;
autosuggestProps?: {
resetValue: () => void;
value: string,
@@ -82,11 +83,24 @@ export class EditableView extends React.Component<EditableProps> {
// }
@action
+ componentDidUpdate() {
+ if (this._editing && this.props.editing === false) {
+ this._inputref.current?.value && this.finalizeEdit(this._inputref.current.value, false, true, false);
+ } else if (this.props.editing !== undefined) {
+ this._editing = this.props.editing;
+ }
+ }
+
+ @action
componentDidMount() {
if (this._ref.current && this.props.onDrop) {
DragManager.MakeDropTarget(this._ref.current, this.props.onDrop.bind(this));
}
}
+ @action
+ componentWillUnmount() {
+ this._inputref.current?.value && this.finalizeEdit(this._inputref.current.value, false, true, false);
+ }
_didShow = false;
@@ -131,14 +145,16 @@ export class EditableView extends React.Component<EditableProps> {
@action
onClick = (e: React.MouseEvent) => {
- e.nativeEvent.stopPropagation();
- if (this._ref.current && this.props.showMenuOnLoad) {
- this.props.menuCallback?.(this._ref.current.getBoundingClientRect().x, this._ref.current.getBoundingClientRect().y);
- } else if (!this.props.onClick?.(e)) {
- this._editing = true;
- this.props.isEditingCallback?.(true);
+ if (this.props.editing !== false) {
+ e.nativeEvent.stopPropagation();
+ if (this._ref.current && this.props.showMenuOnLoad) {
+ this.props.menuCallback?.(this._ref.current.getBoundingClientRect().x, this._ref.current.getBoundingClientRect().y);
+ } else if (!this.props.onClick?.(e)) {
+ this._editing = true;
+ this.props.isEditingCallback?.(true);
+ }
+ e.stopPropagation();
}
- e.stopPropagation();
}
@action
@@ -168,6 +184,7 @@ export class EditableView extends React.Component<EditableProps> {
}
_ref = React.createRef<HTMLDivElement>();
+ _inputref = React.createRef<HTMLInputElement>();
renderEditor() {
return this.props.autosuggestProps
? <Autosuggest
@@ -185,7 +202,7 @@ export class EditableView extends React.Component<EditableProps> {
onChange: this.props.autosuggestProps.onChange
}}
/>
- : <input className="editableView-input"
+ : <input className="editableView-input" ref={this._inputref}
defaultValue={this.props.GetValue()}
onKeyDown={this.onKeyDown}
autoFocus={true}
@@ -211,9 +228,9 @@ export class EditableView extends React.Component<EditableProps> {
setTimeout(() => this.props.autosuggestProps?.resetValue(), 0);
return this.props.contents instanceof ObjectField ? (null) :
<div className={`editableView-container-editing${this.props.oneLine ? "-oneLine" : ""}`} ref={this._ref}
- style={{ display: this.props.display, minHeight: "17px", whiteSpace: "nowrap", height: this.props.height || "auto", maxHeight: this.props.maxHeight }}
+ style={{ display: this.props.display, textOverflow: this.props.overflow, minHeight: "17px", whiteSpace: "nowrap", height: this.props.height || "auto", maxHeight: this.props.maxHeight }}
onClick={this.onClick} placeholder={this.props.placeholder}>
- <span style={{ fontStyle: this.props.fontStyle, fontSize: this.props.fontSize }}>{
+ <span style={{ fontStyle: this.props.fontStyle, fontSize: this.props.fontSize }} >{
this.props.contents ? this.props.contents?.valueOf() : this.props.placeholder?.valueOf()}
</span>
</div>;