Merge branch '21128-toolbar-context-menu'
[arvados-workbench2.git] / src / components / text-field / text-field.tsx
index 1cf9a81d28b497817bf3720f6f53550dea539872..b2a8dd4848602a24eb66fba407f545d0cf992c35 100644 (file)
@@ -2,9 +2,9 @@
 //
 // SPDX-License-Identifier: AGPL-3.0
 
-import * as React from 'react';
+import React from 'react';
 import { WrappedFieldProps } from 'redux-form';
-import { ArvadosTheme } from '~/common/custom-theme';
+import { ArvadosTheme } from 'common/custom-theme';
 import {
     TextField as MaterialTextField,
     StyleRulesCallback,
@@ -13,7 +13,6 @@ import {
     PropTypes
 } from '@material-ui/core';
 import RichTextEditor from 'react-rte';
-import Margin = PropTypes.Margin;
 
 type CssRules = 'textField' | 'rte';
 
@@ -37,7 +36,7 @@ const styles: StyleRulesCallback<CssRules> = (theme: ArvadosTheme) => ({
 type TextFieldProps = WrappedFieldProps & WithStyles<CssRules>;
 
 export const TextField = withStyles(styles)((props: TextFieldProps & {
-    label?: string, autoFocus?: boolean, required?: boolean, select?: boolean, disabled?: boolean, children: React.ReactNode, margin?: Margin, placeholder?: string,
+    label?: string, autoFocus?: boolean, required?: boolean, select?: boolean, disabled?: boolean, children: React.ReactNode, margin?: PropTypes.Margin, placeholder?: string,
     helperText?: string, type?: string,
 }) =>
     <MaterialTextField
@@ -73,7 +72,11 @@ export const RichEditorTextField = withStyles(styles)(
 
         onChange = (value: any) => {
             this.setState({ value });
-            this.props.input.onChange(value.toString('html'));
+            this.props.input.onChange(
+                !!value.getEditorState().getCurrentContent().getPlainText().trim()
+                ? value.toString('html')
+                : null
+            );
         }
 
         render() {