Skip to content

Commit 42d50b3

Browse files
committed
fix: fix readOnly props issue. (#152)
1 parent e70199a commit 42d50b3

File tree

1 file changed

+14
-9
lines changed

1 file changed

+14
-9
lines changed

src/index.tsx

+14-9
Original file line numberDiff line numberDiff line change
@@ -85,29 +85,34 @@ export default React.forwardRef<HTMLTextAreaElement, TextareaCodeEditorProps>((p
8585
[prefixCls, language, htmlStr],
8686
);
8787

88+
const change = (evn: React.ChangeEvent<HTMLTextAreaElement>) => {
89+
setValue(evn.target.value);
90+
onChange && onChange(evn);
91+
};
92+
93+
const keyDown = (evn: React.KeyboardEvent<HTMLTextAreaElement>) => {
94+
if (other.readOnly) return;
95+
if (!other.onKeyDown || other.onKeyDown(evn) !== false) {
96+
shortcuts(evn);
97+
}
98+
};
99+
88100
const textareaProps: React.TextareaHTMLAttributes<HTMLTextAreaElement> = {
89101
autoComplete: 'off',
90102
autoCorrect: 'off',
91103
spellCheck: 'false',
92104
autoCapitalize: 'off',
93105
...other,
94106
placeholder,
95-
onKeyDown: (evn) => {
96-
if (!other.onKeyDown || other.onKeyDown(evn) !== false) {
97-
shortcuts(evn);
98-
}
99-
},
107+
onKeyDown: keyDown,
100108
style: {
101109
...styles.editor,
102110
...styles.textarea,
103111
...contentStyle,
104112
minHeight,
105113
...(placeholder && !value ? { WebkitTextFillColor: 'inherit' } : {}),
106114
},
107-
onChange: (evn) => {
108-
setValue(evn.target.value);
109-
onChange && onChange(evn);
110-
},
115+
onChange: change,
111116
className: `${prefixCls}-text`,
112117
value: value,
113118
};

0 commit comments

Comments
 (0)