Skip to content

Commit d920228

Browse files
committed
fix: use textarea content instead of value
remove custom input handler for textarea class
1 parent e060c23 commit d920228

File tree

3 files changed

+6
-31
lines changed

3 files changed

+6
-31
lines changed

src/lib/js/components/controls/form/textarea.js

-6
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,6 @@ class TextAreaControl extends Control {
88
config: {
99
label: i18n.get('controls.form.textarea'),
1010
},
11-
// actions here will be applied to the preview in the editor
12-
action: {
13-
input: function ({ target: { value } }) {
14-
this.setData?.('value', value)
15-
},
16-
},
1711
meta: {
1812
group: 'common',
1913
icon: 'textarea',
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
1-
import { describe, it, beforeEach, mock } from 'node:test'
1+
import { describe, it, beforeEach } from 'node:test'
22
import assert from 'node:assert'
33
import '../../../../../../tools/__mocks__/ResizeObserver.js'
44
import TextAreaControl from './textarea.js'
5-
import Field from '../../fields/field.js'
6-
import controls from '../index.js'
75

86
describe('TextAreaControl', () => {
97
let controlInstance
@@ -18,7 +16,6 @@ describe('TextAreaControl', () => {
1816

1917
it('should have correct tag and actions', () => {
2018
assert.strictEqual(controlInstance.controlData.tag, 'textarea')
21-
assert.strictEqual(typeof controlInstance.controlData.action.input, 'function')
2219
})
2320

2421
it('should have correct meta information', () => {
@@ -30,21 +27,4 @@ describe('TextAreaControl', () => {
3027
it('should have required attribute set to false', () => {
3128
assert.strictEqual(controlInstance.controlData.attrs.required, false)
3229
})
33-
34-
it('should set data on input', () => {
35-
controls.add(controlInstance)
36-
const controlData = controlInstance.controlData
37-
const fieldData = { ...controlData, config: { controlId: controlData.meta.id } }
38-
const fieldInstance = new Field(fieldData)
39-
const mockSetData = mock.fn()
40-
fieldInstance.setData = mockSetData
41-
42-
fieldInstance.updatePreview()
43-
const textarea = fieldInstance.preview.querySelector('textarea')
44-
textarea.value = 'test value'
45-
textarea.dispatchEvent(new window.Event('input', { bubbles: true }))
46-
47-
assert.strictEqual(mockSetData.mock.calls.length, 1)
48-
assert.deepStrictEqual(mockSetData.mock.calls[0].arguments, ['value', 'test value'])
49-
})
5030
})

src/lib/js/components/fields/field.js

+5-4
Original file line numberDiff line numberDiff line change
@@ -288,17 +288,18 @@ export default class Field extends Component {
288288
}
289289

290290
if (evt.target.contentEditable) {
291-
const parentClassList = evt.target.parentElement.classList
291+
const target = evt.target
292+
const parentClassList = target.parentElement.classList
292293
const isOption = parentClassList.contains('f-checkbox') || parentClassList.contains('f-radio')
293294
if (isOption) {
294-
const option = evt.target.parentElement
295+
const option = target.parentElement
295296
const optionWrap = option.parentElement
296297
const optionIndex = indexOfNode(option, optionWrap)
297-
super.set(`options[${optionIndex}].label`, evt.target.innerHTML)
298+
this.setData(`options[${optionIndex}].label`, target.innerHTML)
298299
return this.debouncedUpdateEditPanels()
299300
}
300301

301-
super.set('content', evt.target.innerHTML)
302+
this.setData('content', target.innerHTML || target.value)
302303
}
303304
},
304305
}

0 commit comments

Comments
 (0)