diff --git a/addons/mail/static/src/components/composer/composer.xml b/addons/mail/static/src/components/composer/composer.xml index 2adca825f27..ac910a2111c 100644 --- a/addons/mail/static/src/components/composer/composer.xml +++ b/addons/mail/static/src/components/composer/composer.xml @@ -84,7 +84,7 @@ 'o-has-current-partner-avatar': composerView.hasCurrentPartnerAvatar, 'rounded-start-3': composerView.isCompact and composerView.hasCurrentPartnerAvatar, }" - record="composerView" + record="composerView.textInput" t-key="composerView.localId" />
diff --git a/addons/mail/static/src/components/composer_text_input/composer_text_input.js b/addons/mail/static/src/components/composer_text_input/composer_text_input.js index 3dc4004c65c..20af03a1544 100644 --- a/addons/mail/static/src/components/composer_text_input/composer_text_input.js +++ b/addons/mail/static/src/components/composer_text_input/composer_text_input.js @@ -1,7 +1,8 @@ /** @odoo-module **/ +import { useComponentToModel } from '@mail/component_hooks/use_component_to_model'; import { useRefToModel } from '@mail/component_hooks/use_ref_to_model'; -import { useUpdate } from '@mail/component_hooks/use_update'; +import { useUpdateToModel } from '@mail/component_hooks/use_update_to_model'; import { registerMessagingComponent } from '@mail/utils/messaging_component'; const { Component } = owl; @@ -13,70 +14,23 @@ export class ComposerTextInput extends Component { */ setup() { super.setup(); + useComponentToModel({ fieldName: 'component' }); useRefToModel({ fieldName: 'mirroredTextareaRef', refName: 'mirroredTextarea' }); useRefToModel({ fieldName: 'textareaRef', refName: 'textarea' }); /** * Updates the composer text input content when composer is mounted * as textarea content can't be changed from the DOM. */ - useUpdate({ func: () => this._update() }); + useUpdateToModel({ methodName: 'onComponentUpdate' }); } - //-------------------------------------------------------------------------- - // Public - //-------------------------------------------------------------------------- - /** - * @returns {ComposerView} + * @returns {ComposerTextInputView} */ - get composerView() { + get composerTextInputView() { return this.props.record; } - //-------------------------------------------------------------------------- - // Private - //-------------------------------------------------------------------------- - - /** - * Determines whether the textarea is empty or not. - * - * @private - * @returns {boolean} - */ - _isEmpty() { - return this.composerView.textareaRef.el.value === ""; - } - - /** - * Updates the content and height of a textarea - * - * @private - */ - _update() { - if (!this.root.el) { - return; - } - if (this.composerView.doFocus) { - this.composerView.update({ doFocus: false }); - if (this.messaging.device.isSmall) { - this.root.el.scrollIntoView(); - } - this.composerView.textareaRef.el.focus(); - } - if (this.composerView.hasToRestoreContent) { - this.composerView.textareaRef.el.value = this.composerView.composer.textInputContent; - if (this.composerView.isFocused) { - this.composerView.textareaRef.el.setSelectionRange( - this.composerView.composer.textInputCursorStart, - this.composerView.composer.textInputCursorEnd, - this.composerView.composer.textInputSelectionDirection, - ); - } - this.composerView.update({ hasToRestoreContent: false }); - } - this.composerView.updateTextInputHeight(); - } - } Object.assign(ComposerTextInput, { diff --git a/addons/mail/static/src/components/composer_text_input/composer_text_input.xml b/addons/mail/static/src/components/composer_text_input/composer_text_input.xml index 3ecdaa0e271..40d4d35e90b 100644 --- a/addons/mail/static/src/components/composer_text_input/composer_text_input.xml +++ b/addons/mail/static/src/components/composer_text_input/composer_text_input.xml @@ -2,18 +2,18 @@ - -
- - + +
+ + -