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

fix: textarea event error #491

Merged
merged 10 commits into from
Jan 19, 2022
8 changes: 8 additions & 0 deletions .changeset/tender-olives-stare.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
'@chakra-ui/vue': patch
'@chakra-ui/nuxt': patch
'@chakra-ui/theme-vue': patch
'chakra-ui-docs': patch
---

Fixes change event lsitener
34 changes: 21 additions & 13 deletions packages/chakra-ui-core/src/CTextarea/CTextarea.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,26 +62,34 @@ const CTextarea = {
const nonNativeEvents = {
input: (value, $e) => {
const emitChange = listeners.change

if (emitChange && $e instanceof Event) {
emitChange(value, $e)
if (typeof emitChange === 'function') {
return emitChange(value, $e)
}
emitChange.forEach(listener => listener(value, $e))
}
Comment on lines -66 to 71
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this change @peoray. Do you think we can add a test case for this change?

}
}
const { nonNative } = extractListeners({ listeners }, nonNativeEvents)

return h(CInput, {
...rest,
props: {
...forwardProps(props),
as: 'textarea'
},
attrs: {
...defaultStyles,
...(data.attrs || {}),
'data-chakra-component': 'CTextarea'
return h(
CInput,
{
...rest,
props: {
...forwardProps(props),
as: 'textarea'
},
attrs: {
...defaultStyles,
...(data.attrs || {}),
'data-chakra-component': 'CTextarea'
},
on: nonNative
},
on: nonNative
}, slots().default)
slots().default
)
}
}

Expand Down
29 changes: 29 additions & 0 deletions packages/chakra-ui-core/src/CTextarea/CTextarea.stories.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ storiesOf('UI | Textarea', module)
mt="2"
placeholder="Here is a sample placeholder"
size="md"
@change="handleChange"
:value="textareaContent"
/>
</CBox>
Expand All @@ -27,3 +28,31 @@ storiesOf('UI | Textarea', module)
action: action()
}
}))
.add('Basic Usage with Event', () => ({
components: { CBox, CTextarea },
template: `
<CBox w="300px">
<CTextarea
v-model="textareaContent"
maxWidth="sm"
mx="auto"
mt="2"
placeholder="Here is a sample placeholder"
size="md"
:value="textareaContent"
@change="handleChange"
/>
</CBox>
`,
data () {
return {
textareaContent: 'Jonathan Bakebwa is awesome'
}
},
methods: {
action: action(),
handleChange (e) {
this.textareaContent = 'You are beautiful :)'
}
}
}))