diff --git a/src/alert/Alert.tsx b/src/alert/Alert.tsx index df6e317211..b57d3ea6b6 100644 --- a/src/alert/Alert.tsx +++ b/src/alert/Alert.tsx @@ -47,7 +47,7 @@ const Alert = forwardRef((props, ref) => { } = useDefaultProps(props, alertDefaultProps); const [closed, setClosed] = React.useState(false); - const [collapsed, setCollapsed] = React.useState(false); + const [collapsed, setCollapsed] = React.useState(true); const iconMap = { success: CheckCircleFilledIcon, @@ -62,7 +62,7 @@ const Alert = forwardRef((props, ref) => { }; const handleCollapse = () => { - setCollapsed(!collapsed); + setCollapsed((collapsed) => !collapsed); }; const renderIconNode = () => { @@ -75,8 +75,8 @@ const Alert = forwardRef((props, ref) => { return (
{message.map((item, index) => { - if (!collapsed) { - if (index < maxLine) { + if (collapsed) { + if (index < +maxLine) { return
{item}
; } } else { @@ -84,9 +84,11 @@ const Alert = forwardRef((props, ref) => { } return true; })} -
- {!collapsed ? t(local.expandText) : t(local.collapseText)} -
+ {+maxLine < message.length && ( +
+ {collapsed ? t(local.expandText) : t(local.collapseText)} +
+ )}
); }