Class RichTextEditor
- All Implemented Interfaces:
AttachNotifier,CompositionNotifier,DetachNotifier,HasElement,HasEnabled,HasSize,HasStyle,HasTheme,HasValue<AbstractField.ComponentValueChangeEvent<RichTextEditor,,String>, String> HasValueAndElement<AbstractField.ComponentValueChangeEvent<RichTextEditor,,String>, String> InputNotifier,KeyNotifier,HasThemeVariant<RichTextEditorVariant>,HasValueChangeMode,Serializable
The value of the rich text editor is in the HTML format. The
setValue and getValue methods
use the HTML format by default.
To get and set the value in the
Quill Delta format, use
asDelta(), HasValue.getValue() and
HasValue.setValue(String).
- Author:
- Vaadin Ltd
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classThe internationalization properties forRichTextEditor.Nested classes/interfaces inherited from class com.vaadin.flow.component.AbstractField
AbstractField.ComponentValueChangeEvent<C extends Component,V> Nested classes/interfaces inherited from interface com.vaadin.flow.component.HasValue
HasValue.ValueChangeEvent<V>, HasValue.ValueChangeListener<E extends HasValue.ValueChangeEvent<?>> -
Field Summary
Fields inherited from interface com.vaadin.flow.data.value.HasValueChangeMode
DEFAULT_CHANGE_TIMEOUT -
Constructor Summary
ConstructorsConstructorDescriptionConstructs an emptyRichTextEditor.RichTextEditor(HasValue.ValueChangeListener<? super AbstractField.ComponentValueChangeEvent<RichTextEditor, String>> listener) Constructs an emptyRichTextEditorwith a value change listener. -
Method Summary
Modifier and TypeMethodDescriptionasDelta()Gets an instance ofHasValuefor the editor in the Quill Delta format.asHtml()Gets an instance ofHasValuefor the editor in the HTML format.Gets an unmodifiable list of colors in HEX format used by the text color picker and background color picker controls of the text editor.Deprecated.since v24 the RichTextEditor uses the HTML value by default.getI18n()Gets the internationalization object previously set for this component.getValue()Returns the current value of the text editor in HTML format.Gets current value change mode of the component.booleanisEmpty()Returns whether the value is considered to be empty.protected voidonAttach(AttachEvent attachEvent) Called when the component is attached to a UI.voidsetColorOptions(List<String> colorOptions) Sets the list of colors in HEX format to use by the text color picker and background color picker controls of the text editor.voidSets the internationalization object for this component.protected voidsetPresentationValue(String newPresentationValue) Updates the presentation of this field to display the provided value.voidSets the value of this editor in HTML format.voidsetValueChangeMode(ValueChangeMode valueChangeMode) Sets new value change mode for the component.Methods inherited from class com.vaadin.flow.component.AbstractSinglePropertyField
getSynchronizationRegistration, hasValidValue, setSynchronizedEventMethods inherited from class com.vaadin.flow.component.AbstractField
addValueChangeListener, getEmptyValue, setModelValue, valueEqualsMethods inherited from class com.vaadin.flow.component.Component
addListener, findAncestor, fireEvent, from, get, getChildren, getElement, getEventBus, getId, getListeners, getLocale, getParent, getTranslation, getTranslation, getTranslation, getTranslation, getTranslation, getTranslation, getUI, hasListener, isAttached, isTemplateMapped, isVisible, onDetach, onEnabledStateChanged, removeFromParent, scrollIntoView, scrollIntoView, set, setElement, setId, setVisibleMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface com.vaadin.flow.component.AttachNotifier
addAttachListenerMethods inherited from interface com.vaadin.flow.component.CompositionNotifier
addCompositionEndListener, addCompositionStartListener, addCompositionUpdateListenerMethods inherited from interface com.vaadin.flow.component.DetachNotifier
addDetachListenerMethods inherited from interface com.vaadin.flow.component.HasElement
getElementMethods inherited from interface com.vaadin.flow.component.HasEnabled
isEnabled, setEnabledMethods inherited from interface com.vaadin.flow.component.HasSize
getHeight, getHeightUnit, getMaxHeight, getMaxWidth, getMinHeight, getMinWidth, getWidth, getWidthUnit, setHeight, setHeight, setHeightFull, setMaxHeight, setMaxHeight, setMaxWidth, setMaxWidth, setMinHeight, setMinHeight, setMinWidth, setMinWidth, setSizeFull, setSizeUndefined, setWidth, setWidth, setWidthFullMethods inherited from interface com.vaadin.flow.component.HasStyle
addClassName, addClassNames, getClassName, getClassNames, getStyle, hasClassName, removeClassName, removeClassNames, setClassName, setClassNameMethods inherited from interface com.vaadin.flow.component.HasTheme
addThemeName, addThemeNames, getThemeName, getThemeNames, hasThemeName, removeThemeName, removeThemeNames, setThemeName, setThemeNameMethods inherited from interface com.vaadin.flow.component.shared.HasThemeVariant
addThemeVariants, removeThemeVariants, setThemeVariant, setThemeVariants, setThemeVariantsMethods inherited from interface com.vaadin.flow.component.HasValue
clear, getOptionalValueMethods inherited from interface com.vaadin.flow.component.HasValueAndElement
isReadOnly, isRequiredIndicatorVisible, setReadOnly, setRequiredIndicatorVisibleMethods inherited from interface com.vaadin.flow.data.value.HasValueChangeMode
getValueChangeTimeout, setValueChangeTimeoutMethods inherited from interface com.vaadin.flow.component.InputNotifier
addInputListenerMethods inherited from interface com.vaadin.flow.component.KeyNotifier
addKeyDownListener, addKeyDownListener, addKeyPressListener, addKeyPressListener, addKeyUpListener, addKeyUpListener
-
Constructor Details
-
RichTextEditor
public RichTextEditor()Constructs an emptyRichTextEditor. -
RichTextEditor
public RichTextEditor(HasValue.ValueChangeListener<? super AbstractField.ComponentValueChangeEvent<RichTextEditor, String>> listener) Constructs an emptyRichTextEditorwith a value change listener.- Parameters:
listener- the value change listener- See Also:
-
-
Method Details
-
getI18n
Gets the internationalization object previously set for this component.NOTE: Updating the instance that is returned from this method will not update the component if not set again using
setI18n(RichTextEditorI18n)- Returns:
- the i18n object or
nullif no i18n object has been set
-
setI18n
Sets the internationalization object for this component.- Parameters:
i18n- the i18n object, notnull
-
onAttach
Description copied from class:ComponentCalled when the component is attached to a UI.This method is invoked before the
Make sure to callAttachEventis fired for the component.super.onAttachwhen overriding this method. -
getValueChangeMode
Gets current value change mode of the component.The default value is
ValueChangeMode.ON_CHANGE.- Specified by:
getValueChangeModein interfaceHasValueChangeMode- Returns:
- current value change mode of the component, or
nullif the value is not synchronized
-
setValueChangeMode
Description copied from interface:HasValueChangeModeSets new value change mode for the component.- Specified by:
setValueChangeModein interfaceHasValueChangeMode- Parameters:
valueChangeMode- new value change mode, ornullto disable the value synchronization
-
setValue
Sets the value of this editor in HTML format. If the new value is not equal togetValue(), fires a value change event. ThrowsNullPointerException, if the value is null.Note:
Binderwill take care of thenullconversion when integrates with the editor, as long as no new converter is defined.Since v24, this method only accepts values in the HTML format, whereas in v23 and earlier this method would accept values in the Delta format. In order to prevent data corruption, passing a value that starts with either
[or{will now throw anIllegalArgumentException, as it might indicate that the value is in the Delta format. In order to keep using the Delta format, useasDelta(), which allows setting, retrieving, and binding the value using Binder, in the Delta format. In order to pass an HTML value starting with either characters, either wrap the value in a valid HTML tag, such as<p>, or useasHtml()which does not include this check.- Specified by:
setValuein interfaceHasValue<AbstractField.ComponentValueChangeEvent<RichTextEditor,String>, String> - Overrides:
setValuein classAbstractField<RichTextEditor,String> - Parameters:
value- the new value in HTML format, notnull- See Also:
-
setPresentationValue
Description copied from class:AbstractFieldUpdates the presentation of this field to display the provided value. Subclasses should override this method to show the value to the user. This is typically done by setting an element property or by applying changes to child components.If
AbstractField.setModelValue(Object, boolean)is called from within this method, the value of the last invocation will be used as the model value instead of the value passed to this method. In this caseAbstractField.setPresentationValue(Object)will not be called again. Changing the provided value might be useful if the provided value is sanitized.See
AbstractFieldfor an overall description on the difference between model values and presentation values.- Overrides:
setPresentationValuein classAbstractSinglePropertyField<RichTextEditor,String> - Parameters:
newPresentationValue- the new value to show
-
isEmpty
public boolean isEmpty()Returns whether the value is considered to be empty.As the editor's HTML value always contains a minimal markup, this does not check if the value is an empty string. Instead, this method considers the value to not be empty if the user has added some content, which can be:
- Text, whitespaces or line breaks
- An image
Note that a single empty HTML tag, such as a heading, blockquote, etc., is not considered as content.
- Specified by:
isEmptyin interfaceHasValue<AbstractField.ComponentValueChangeEvent<RichTextEditor,String>, String> - Overrides:
isEmptyin classAbstractField<RichTextEditor,String> - Returns:
trueif considered empty;falseif not
-
getValue
Returns the current value of the text editor in HTML format. By default, the empty editor will return an empty string.- Specified by:
getValuein interfaceHasValue<AbstractField.ComponentValueChangeEvent<RichTextEditor,String>, String> - Overrides:
getValuein classAbstractField<RichTextEditor,String> - Returns:
- the current value.
- See Also:
-
getHtmlValue
Deprecated.since v24 the RichTextEditor uses the HTML value by default. UsegetValue()instead.The value of the editor in HTML format.- Returns:
- the editor value in HTML format
- See Also:
-
getColorOptions
Gets an unmodifiable list of colors in HEX format used by the text color picker and background color picker controls of the text editor.Returns
nullby default, which means the web component shows a default color palette.- Returns:
- an unmodifiable list of colors options
- Since:
- 24.5
-
setColorOptions
Sets the list of colors in HEX format to use by the text color picker and background color picker controls of the text editor.- Parameters:
colorOptions- the list of colors to set, not null- Since:
- 24.5
-
asHtml
Gets an instance ofHasValuefor the editor in the HTML format. Can be used for binding the value withBinder.Note that since v24, the RichTextEditor uses the HTML value by default. Instead of using this wrapper,
getValue()andsetValue(String)can be used directly, andRichTextEditorcan be used for binding the HTML value using Binder. This method is not intended to be deprecated as it keeps the legacy behavior that allows passing values starting with either[or{, which is not allowed when usingsetValue(String).- Returns:
- an instance of
HasValue
-
asDelta
Gets an instance ofHasValuefor the editor in the Quill Delta format. Can be used for binding the value withBinder.- Returns:
- an instance of
HasValue
-