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

Commit 09c90d8

Browse files
Merge pull request #491 from chakra-ui/fix/textarea-event-error
fix: textarea event error
2 parents 2c04cfe + 3d2ab89 commit 09c90d8

File tree

3 files changed

+58
-13
lines changed

3 files changed

+58
-13
lines changed

.changeset/tender-olives-stare.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
'@chakra-ui/vue': patch
3+
'@chakra-ui/nuxt': patch
4+
'@chakra-ui/theme-vue': patch
5+
'chakra-ui-docs': patch
6+
---
7+
8+
Fixes change event lsitener

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: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ storiesOf('UI | Textarea', module)
1414
mt="2"
1515
placeholder="Here is a sample placeholder"
1616
size="md"
17+
@change="handleChange"
1718
:value="textareaContent"
1819
/>
1920
</CBox>
@@ -27,3 +28,31 @@ storiesOf('UI | Textarea', module)
2728
action: action()
2829
}
2930
}))
31+
.add('Basic Usage with Event', () => ({
32+
components: { CBox, CTextarea },
33+
template: `
34+
<CBox w="300px">
35+
<CTextarea
36+
v-model="textareaContent"
37+
maxWidth="sm"
38+
mx="auto"
39+
mt="2"
40+
placeholder="Here is a sample placeholder"
41+
size="md"
42+
:value="textareaContent"
43+
@change="handleChange"
44+
/>
45+
</CBox>
46+
`,
47+
data () {
48+
return {
49+
textareaContent: 'Jonathan Bakebwa is awesome'
50+
}
51+
},
52+
methods: {
53+
action: action(),
54+
handleChange (e) {
55+
this.textareaContent = 'You are beautiful :)'
56+
}
57+
}
58+
}))

0 commit comments

Comments
 (0)