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

Commit 7b0aede

Browse files
committed
fix(ctextarea): works with v-model
1 parent 22d60f6 commit 7b0aede

File tree

3 files changed

+125
-1
lines changed

3 files changed

+125
-1
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ const CTextarea = {
2626
name: 'CTextarea',
2727
functional: true,
2828
model: {
29-
prop: 'inputValue',
29+
prop: 'value',
3030
event: 'change'
3131
},
3232
props: {
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import { CTextarea } from '../..'
2+
import { render, screen, userEvent } from '@/tests/test-utils'
3+
4+
const renderComponent = (props) => {
5+
const inlineAttrs = (props && props.inlineAttrs) || ''
6+
const base = {
7+
data: () => ({ text: 'hello' }),
8+
components: { CTextarea },
9+
template: `<CTextarea data-testid="textarea" placeholder="textarea placeholder" v-model="text" ${inlineAttrs}/>`,
10+
...props
11+
}
12+
return render(base)
13+
}
14+
15+
test('should render correctly', () => {
16+
const { asFragment } = renderComponent()
17+
expect(asFragment()).toMatchSnapshot()
18+
})
19+
20+
test('v-model works', () => {
21+
renderComponent()
22+
const textarea = screen.getByTestId('textarea')
23+
24+
userEvent.type(textarea, ' world')
25+
expect(textarea).toHaveValue('hello world')
26+
})
27+
28+
test('readonly textarea renders correctly', () => {
29+
renderComponent({ inlineAttrs: 'isReadOnly' })
30+
const textarea = screen.getByTestId('textarea')
31+
32+
expect(textarea).toHaveAttribute('readonly')
33+
})
34+
35+
test('disabled textarea renders correctly', () => {
36+
renderComponent({ inlineAttrs: 'isDisabled' })
37+
const textarea = screen.getByTestId('textarea')
38+
39+
expect(textarea).toHaveAttribute('disabled')
40+
})
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`should render correctly 1`] = `
4+
<DocumentFragment>
5+
.emotion-0 {
6+
width: 100%;
7+
display: -webkit-box;
8+
display: -webkit-flex;
9+
display: -ms-flexbox;
10+
display: flex;
11+
-webkit-align-items: center;
12+
-webkit-box-align: center;
13+
-ms-flex-align: center;
14+
align-items: center;
15+
position: relative;
16+
-webkit-transition: all 0.2s;
17+
transition: all 0.2s;
18+
outline: 2px solid transparent;
19+
outline-offset: 2px;
20+
-webkit-appearance: none;
21+
-moz-appearance: none;
22+
-ms-appearance: none;
23+
appearance: none;
24+
font-size: var(--chakra-fontSizes-md);
25+
-webkit-padding-start: var(--chakra-space-4);
26+
padding-inline-start: var(--chakra-space-4);
27+
-webkit-padding-end: var(--chakra-space-4);
28+
padding-inline-end: var(--chakra-space-4);
29+
height: var(--chakra-sizes-10);
30+
line-height: var(--chakra-lineHeights-shorter);
31+
border-radius: var(--chakra-radii-md);
32+
border-width: 1px;
33+
border-color: inherit;
34+
background: var(--chakra-colors-white);
35+
font-family: var(--chakra-fonts-body);
36+
padding-top: 8px;
37+
padding-bottom: 8px;
38+
min-height: 80px;
39+
}
40+
41+
.emotion-0[aria-readonly=true],
42+
.emotion-0[readonly],
43+
.emotion-0[data-readonly] {
44+
background: var(--chakra-colors-transparent);
45+
box-shadow: none!important;
46+
-webkit-user-select: all;
47+
-moz-user-select: all;
48+
-ms-user-select: all;
49+
user-select: all;
50+
}
51+
52+
.emotion-0:hover,
53+
.emotion-0[data-hover] {
54+
border-color: var(--chakra-colors-gray-300);
55+
}
56+
57+
.emotion-0[disabled],
58+
.emotion-0[aria-disabled=true],
59+
.emotion-0[data-disabled] {
60+
opacity: 0.4;
61+
cursor: not-allowed;
62+
}
63+
64+
.emotion-0:focus,
65+
.emotion-0[data-focus] {
66+
z-index: 1;
67+
border-color: #7db1ff;
68+
box-shadow: 0 0 0 1px #7db1ff;
69+
}
70+
71+
.emotion-0[aria-invalid=true],
72+
.emotion-0[data-invalid] {
73+
border-color: #e66673;
74+
box-shadow: 0 0 0 1px #e66673;
75+
}
76+
77+
<textarea
78+
class="emotion-0"
79+
data-chakra-component="CTextarea"
80+
data-testid="textarea"
81+
placeholder="textarea placeholder"
82+
/>
83+
</DocumentFragment>
84+
`;

0 commit comments

Comments
 (0)