@@ -127,6 +127,13 @@ const dynamicSlotConfig: Record<string, (slotName: string) => boolean> = {
127127 't-chat-item' : ( slotName ) => slotName === 'actionbar' ,
128128} ;
129129
130+ /**
131+ * 某些prop与slot同名,但应该作为prop而非slot传递
132+ * 如t-button的icon prop不应该渲染到slot中
133+ * 同时,这些prop不应该作为attribute传递
134+ */
135+ const propsNotAsSlot = [ 'icon' ] ;
136+
130137const reactify = < T extends AnyProps = AnyProps > (
131138 WC : string ,
132139) : React . ForwardRefExoticComponent < Omit < T , 'ref' > & React . RefAttributes < HTMLElement | undefined > > => {
@@ -204,7 +211,10 @@ const reactify = <T extends AnyProps = AnyProps>(
204211 // 如果val是ReactNode,直接渲染到slot
205212 else if ( isValidReactNode ( val ) ) {
206213 // 先设置属性,让组件知道这个prop有值
207- webComponent [ prop ] = true ;
214+ // 组件不需要渲染 propsNotAsSlot
215+ if ( ! propsNotAsSlot . includes ( prop ) ) {
216+ webComponent [ prop ] = true ;
217+ }
208218
209219 // 使用微任务延迟渲染,确保在当前渲染周期完成后执行
210220 Promise . resolve ( ) . then ( ( ) => {
@@ -512,8 +522,14 @@ const reactify = <T extends AnyProps = AnyProps>(
512522
513523 render ( ) {
514524 const { children, className, ...rest } = this . props ;
515-
516- return createElement ( WC , { class : className , ...rest , ref : this . ref } , children ) ;
525+ // 过滤掉不应该作为attribute传递的props,它们会在update()中处理
526+ const filteredProps : Record < string , any > = { } ;
527+ Object . keys ( rest ) . forEach ( ( key ) => {
528+ if ( ! propsNotAsSlot . includes ( key ) ) {
529+ filteredProps [ key ] = rest [ key ] ;
530+ }
531+ } ) ;
532+ return createElement ( WC , { class : className , ...filteredProps , ref : this . ref } , children ) ;
517533 }
518534 }
519535
0 commit comments