Skip to content
This repository was archived by the owner on Sep 20, 2024. It is now read-only.

Commit 83ab8c5

Browse files
committed
fix(textarea): allow change event
1 parent 8984d3c commit 83ab8c5

File tree

2 files changed

+32
-25
lines changed

2 files changed

+32
-25
lines changed

packages/chakra-ui-core/src/CTextarea/CTextarea.js

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -62,26 +62,34 @@ const CTextarea = {
6262
const nonNativeEvents = {
6363
input: (value, $e) => {
6464
const emitChange = listeners.change
65+
6566
if (emitChange && $e instanceof Event) {
66-
emitChange(value, $e)
67+
if (typeof emitChange === 'function') {
68+
return emitChange(value, $e)
69+
}
70+
emitChange.forEach(listener => listener(value, $e))
6771
}
6872
}
6973
}
7074
const { nonNative } = extractListeners({ listeners }, nonNativeEvents)
7175

72-
return h(CInput, {
73-
...rest,
74-
props: {
75-
...forwardProps(props),
76-
as: 'textarea'
77-
},
78-
attrs: {
79-
...defaultStyles,
80-
...(data.attrs || {}),
81-
'data-chakra-component': 'CTextarea'
76+
return h(
77+
CInput,
78+
{
79+
...rest,
80+
props: {
81+
...forwardProps(props),
82+
as: 'textarea'
83+
},
84+
attrs: {
85+
...defaultStyles,
86+
...(data.attrs || {}),
87+
'data-chakra-component': 'CTextarea'
88+
},
89+
on: nonNative
8290
},
83-
on: nonNative
84-
}, slots().default)
91+
slots().default
92+
)
8593
}
8694
}
8795

packages/chakra-ui-core/src/CTextarea/CTextarea.stories.js

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,9 @@ import { storiesOf } from '@storybook/vue'
22
import { action } from '@storybook/addon-actions'
33
import { CBox, CTextarea } from '..'
44

5-
storiesOf('UI | Textarea', module)
6-
.add('Basic Usage', () => ({
7-
components: { CBox, CTextarea },
8-
template: `
5+
storiesOf('UI | Textarea', module).add('Basic Usage', () => ({
6+
components: { CBox, CTextarea },
7+
template: `
98
<CBox w="300px">
109
<CTextarea
1110
v-model="textareaContent"
@@ -18,12 +17,12 @@ storiesOf('UI | Textarea', module)
1817
/>
1918
</CBox>
2019
`,
21-
data () {
22-
return {
23-
textareaContent: 'Jonathan Bakebwa is awesome'
24-
}
25-
},
26-
methods: {
27-
action: action()
20+
data () {
21+
return {
22+
textareaContent: 'Jonathan Bakebwa is awesome'
2823
}
29-
}))
24+
},
25+
methods: {
26+
action: action()
27+
}
28+
}))

0 commit comments

Comments
 (0)