Skip to content

Commit 80f23c8

Browse files
committed
feat: 富文本编辑器组件添加onBlur事件
1 parent fed8792 commit 80f23c8

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

client/packages/barda/src/comps/comps/richTextEditorComp.tsx

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { StringControl } from "comps/controls/codeControl";
22
import { BoolControl } from "comps/controls/boolControl";
33
import { stringExposingStateControl } from "comps/controls/codeStateControl";
44
import { AutoHeightControl } from "comps/controls/autoHeightControl";
5-
import { ChangeEventHandlerControl } from "comps/controls/eventHandlerControl";
5+
import { blurEvent, changeEvent, eventHandlerControl } from "comps/controls/eventHandlerControl";
66
import { UICompBuilder, withDefault } from "comps/generators";
77
import { NameConfig, NameConfigHidden, withExposingConfigs, depsConfig } from "comps/generators/withExposing";
88
import { Section, sectionNames } from "barda-design";
@@ -208,7 +208,7 @@ const childrenMap = {
208208
autoHeight: AutoHeightControl,
209209
autoTimestamp: BoolControl,
210210
placeholder: withDefault(StringControl, trans("richTextEditor.placeholder")),
211-
onEvent: ChangeEventHandlerControl,
211+
onEvent: eventHandlerControl([changeEvent, blurEvent] as const),
212212
style: styleControl(RichTextEditorStyle),
213213

214214
...formDataChildren,
@@ -232,6 +232,7 @@ interface IProps {
232232
autoTimestamp: boolean;
233233
autoHeight: boolean;
234234
onChange: (value: string) => void;
235+
onBlur: () => void;
235236
$style: RichTextEditorStyleType;
236237
}
237238

@@ -530,6 +531,10 @@ function RichTextEditor(props: IProps) {
530531
onChangeRef.current(value);
531532
};
532533

534+
const handleBlur = () => {
535+
props.onBlur?.();
536+
};
537+
533538
useEffect(() => {
534539
let finalValue = props.value;
535540
if (!/^<\w+>.+<\/\w+>$/.test(props.value)) {
@@ -596,6 +601,7 @@ function RichTextEditor(props: IProps) {
596601
placeholder={props.placeholder}
597602
readOnly={props.readOnly}
598603
onChange={handleChange}
604+
onBlur={handleBlur}
599605
/>
600606
</Suspense>
601607
</Wrapper>
@@ -608,6 +614,10 @@ const RichTextEditorCompBase = new UICompBuilder(childrenMap, (props) => {
608614
props.onEvent("change");
609615
};
610616

617+
const handleBlur = () => {
618+
props.onEvent("blur");
619+
};
620+
611621
return (
612622
<RichTextEditor
613623
autoHeight={props.autoHeight}
@@ -617,6 +627,7 @@ const RichTextEditorCompBase = new UICompBuilder(childrenMap, (props) => {
617627
value={props.value.value}
618628
placeholder={props.placeholder}
619629
onChange={handleChange}
630+
onBlur={handleBlur}
620631
$style={props.style}
621632
/>
622633
);

0 commit comments

Comments
 (0)