diff --git a/packages/ava-react/src/NarrativeTextVis/phrases/Phrase.tsx b/packages/ava-react/src/NarrativeTextVis/phrases/Phrase.tsx index 694f2285..8cf5e33c 100644 --- a/packages/ava-react/src/NarrativeTextVis/phrases/Phrase.tsx +++ b/packages/ava-react/src/NarrativeTextVis/phrases/Phrase.tsx @@ -112,26 +112,21 @@ export const Phrase: React.FC = ({ }) => { const themeStyles = { size, theme }; - const onClick = () => { - events?.onClickPhrase?.(phrase); - }; - - const onMouseEnter = () => { - events?.onMouseEnterPhrase?.(phrase); - }; - - const onMouseLeave = () => { - events?.onMouseLeavePhrase?.(phrase); - }; - - let defaultText = !isEmpty(events) ? ( - - {phrase.value} - - ) : ( - <>{phrase.value} - ); - + const eventProps = !isEmpty(events) + ? { + onClick: () => { + events?.onClickPhrase?.(phrase); + }, + onMouseEnter: () => { + events?.onMouseEnterPhrase?.(phrase); + }, + onMouseLeave: () => { + events?.onMouseLeavePhrase?.(phrase); + }, + } + : {}; + + let defaultText = <>{phrase.value}; if (isTextPhrase(phrase)) { if (phrase.bold) defaultText = {defaultText}; if (phrase.italic) defaultText = {defaultText}; @@ -143,7 +138,7 @@ export const Phrase: React.FC = ({ ); return ( - + {defaultText} ); @@ -153,7 +148,7 @@ export const Phrase: React.FC = ({ // 使用 pre 标签渲染特殊转义字符 if (isEscapePhrase(phrase)) return ( -
+      
         {phrase.value}
       
); @@ -163,6 +158,7 @@ export const Phrase: React.FC = ({ if (isFormulaPhrase(phrase)) return ( = ({ ); if (isImagePhrase(phrase)) { - return {phrase.alt}; + return ( + {phrase.alt} + ); } const descriptor = pluginManager?.getPhraseDescriptorBySpec(phrase); @@ -185,5 +183,5 @@ export const Phrase: React.FC = ({ return <>{renderPhraseByDescriptor({ spec: phrase, descriptor, themeStyles, events })}; } - return defaultText; + return !isEmpty(events) ? defaultText : defaultText; };