From d920228b8daff91013200ed70b4c4138cbd7139c Mon Sep 17 00:00:00 2001 From: Kevin Chappell Date: Mon, 30 Dec 2024 14:34:02 -0800 Subject: [PATCH] fix: use textarea content instead of value remove custom input handler for textarea class --- .../js/components/controls/form/textarea.js | 6 ----- .../controls/form/textarea.test.mjs | 22 +------------------ src/lib/js/components/fields/field.js | 9 ++++---- 3 files changed, 6 insertions(+), 31 deletions(-) diff --git a/src/lib/js/components/controls/form/textarea.js b/src/lib/js/components/controls/form/textarea.js index ba90f313..e7540358 100644 --- a/src/lib/js/components/controls/form/textarea.js +++ b/src/lib/js/components/controls/form/textarea.js @@ -8,12 +8,6 @@ class TextAreaControl extends Control { config: { label: i18n.get('controls.form.textarea'), }, - // actions here will be applied to the preview in the editor - action: { - input: function ({ target: { value } }) { - this.setData?.('value', value) - }, - }, meta: { group: 'common', icon: 'textarea', diff --git a/src/lib/js/components/controls/form/textarea.test.mjs b/src/lib/js/components/controls/form/textarea.test.mjs index 275fe527..cd75657c 100644 --- a/src/lib/js/components/controls/form/textarea.test.mjs +++ b/src/lib/js/components/controls/form/textarea.test.mjs @@ -1,9 +1,7 @@ -import { describe, it, beforeEach, mock } from 'node:test' +import { describe, it, beforeEach } from 'node:test' import assert from 'node:assert' import '../../../../../../tools/__mocks__/ResizeObserver.js' import TextAreaControl from './textarea.js' -import Field from '../../fields/field.js' -import controls from '../index.js' describe('TextAreaControl', () => { let controlInstance @@ -18,7 +16,6 @@ describe('TextAreaControl', () => { it('should have correct tag and actions', () => { assert.strictEqual(controlInstance.controlData.tag, 'textarea') - assert.strictEqual(typeof controlInstance.controlData.action.input, 'function') }) it('should have correct meta information', () => { @@ -30,21 +27,4 @@ describe('TextAreaControl', () => { it('should have required attribute set to false', () => { assert.strictEqual(controlInstance.controlData.attrs.required, false) }) - - it('should set data on input', () => { - controls.add(controlInstance) - const controlData = controlInstance.controlData - const fieldData = { ...controlData, config: { controlId: controlData.meta.id } } - const fieldInstance = new Field(fieldData) - const mockSetData = mock.fn() - fieldInstance.setData = mockSetData - - fieldInstance.updatePreview() - const textarea = fieldInstance.preview.querySelector('textarea') - textarea.value = 'test value' - textarea.dispatchEvent(new window.Event('input', { bubbles: true })) - - assert.strictEqual(mockSetData.mock.calls.length, 1) - assert.deepStrictEqual(mockSetData.mock.calls[0].arguments, ['value', 'test value']) - }) }) diff --git a/src/lib/js/components/fields/field.js b/src/lib/js/components/fields/field.js index 218642d9..46739f36 100644 --- a/src/lib/js/components/fields/field.js +++ b/src/lib/js/components/fields/field.js @@ -288,17 +288,18 @@ export default class Field extends Component { } if (evt.target.contentEditable) { - const parentClassList = evt.target.parentElement.classList + const target = evt.target + const parentClassList = target.parentElement.classList const isOption = parentClassList.contains('f-checkbox') || parentClassList.contains('f-radio') if (isOption) { - const option = evt.target.parentElement + const option = target.parentElement const optionWrap = option.parentElement const optionIndex = indexOfNode(option, optionWrap) - super.set(`options[${optionIndex}].label`, evt.target.innerHTML) + this.setData(`options[${optionIndex}].label`, target.innerHTML) return this.debouncedUpdateEditPanels() } - super.set('content', evt.target.innerHTML) + this.setData('content', target.innerHTML || target.value) } }, }