diff --git a/packages/card/index.js b/packages/card/index.js index e208e532f..0ed7ad44f 100644 --- a/packages/card/index.js +++ b/packages/card/index.js @@ -1,4 +1,5 @@ import { use, isDef } from '../utils'; +import { inherit } from '../utils/functional'; import Tag from '../tag'; const [sfc, bem] = use('card'); @@ -68,7 +69,7 @@ function Card(h, props, slots, ctx) { ); return ( -
+
{Thumb}
diff --git a/packages/cell-group/index.js b/packages/cell-group/index.js index f83005d53..1b0203c4f 100644 --- a/packages/cell-group/index.js +++ b/packages/cell-group/index.js @@ -1,4 +1,5 @@ import { use } from '../utils'; +import { inherit } from '../utils/functional'; const [sfc, bem] = use('cell-group'); @@ -6,7 +7,7 @@ function CellGroup(h, props, slots, ctx) { return (
{slots.default && slots.default()}
diff --git a/packages/goods-action/index.js b/packages/goods-action/index.js index 2ac8e95aa..d6c0649e9 100644 --- a/packages/goods-action/index.js +++ b/packages/goods-action/index.js @@ -1,10 +1,11 @@ import { use } from '../utils'; +import { inherit } from '../utils/functional'; const [sfc, bem] = use('goods-action'); function GoodsAction(h, props, slots, ctx) { return ( -
+
{slots.default && slots.default()}
); diff --git a/packages/icon/index.js b/packages/icon/index.js index 1777814be..71bc515e7 100644 --- a/packages/icon/index.js +++ b/packages/icon/index.js @@ -1,4 +1,5 @@ import { use } from '../utils'; +import { inherit } from '../utils/functional'; import Info from '../info'; import isSrc from '../utils/validate/src'; @@ -17,7 +18,7 @@ function Icon(h, props, slots, ctx) { color: props.color, fontSize: props.size }} - {...ctx.data} + {...inherit(ctx, true)} > {ctx.default && ctx.default()} {urlIcon && } diff --git a/packages/info/index.js b/packages/info/index.js index df544617c..08aa77a1f 100644 --- a/packages/info/index.js +++ b/packages/info/index.js @@ -1,11 +1,12 @@ import { use, isDef } from '../utils'; +import { inherit } from '../utils/functional'; const [sfc, bem] = use('info'); function Info(h, props, slots, ctx) { return ( isDef(props.info) && ( -
+
{props.info}
) diff --git a/packages/loading/index.js b/packages/loading/index.js index 44bd8c2ad..a7772857b 100644 --- a/packages/loading/index.js +++ b/packages/loading/index.js @@ -1,4 +1,5 @@ import { use } from '../utils'; +import { inherit } from '../utils/functional'; const [sfc, bem] = use('loading'); const DEFAULT_COLOR = '#c9c9c9'; @@ -28,7 +29,7 @@ function Loading(h, props, slots, ctx) { ); return ( -
+
{Spin} {Circular} diff --git a/packages/panel/index.js b/packages/panel/index.js index 63f37f600..70cb93829 100644 --- a/packages/panel/index.js +++ b/packages/panel/index.js @@ -1,29 +1,36 @@ import { use } from '../utils'; import Cell from '../cell'; import CellGroup from '../cell-group'; +import { inherit } from '../utils/functional'; const [sfc, bem] = use('panel'); function Panel(h, props, slots, ctx) { + const Content = () => [ + slots.header ? ( + slots.header() + ) : ( + + ), +
{slots.default && slots.default()}
, + slots.footer && ( +
{slots.footer()}
+ ) + ]; + return ( - - {slots.header ? ( - slots.header() - ) : ( - - )} -
{slots.default && slots.default()}
- {slots.footer && ( -
{slots.footer()}
- )} -
+ ); } diff --git a/packages/password-input/index.js b/packages/password-input/index.js index 4626b6c33..b65933fa4 100644 --- a/packages/password-input/index.js +++ b/packages/password-input/index.js @@ -1,5 +1,5 @@ import { use } from '../utils'; -import { emit } from '../utils/functional'; +import { emit, inherit } from '../utils/functional'; const [sfc, bem] = use('password-input'); @@ -23,7 +23,7 @@ function PasswordInput(h, props, slots, ctx) { event.stopPropagation(); emit(ctx, 'focus', event); }} - {...ctx.data} + {...inherit(ctx, true)} > {Points} diff --git a/packages/tag/index.js b/packages/tag/index.js index 82a703737..7ba243da6 100644 --- a/packages/tag/index.js +++ b/packages/tag/index.js @@ -1,4 +1,5 @@ import { use } from '../utils'; +import { inherit } from '../utils/functional'; import { RED, BLUE, GREEN, GRAY_DARK } from '../utils/color'; const [sfc, bem] = use('tag'); @@ -29,7 +30,7 @@ function Tag(h, props, slots, ctx) { 'van-hairline--surround': plain } ]} - {...ctx.data} + {...inherit(ctx, true)} > {slots.default && slots.default()}
diff --git a/packages/utils/functional.ts b/packages/utils/functional.ts index 3242d790d..303c984ef 100644 --- a/packages/utils/functional.ts +++ b/packages/utils/functional.ts @@ -21,8 +21,8 @@ const inheritKey = [ const mapInheritKey: ObjectIndex = { nativeOn: 'on' }; // inherit partial context, map nativeOn to on -export function inherit(context: Context): InheritContext { - return inheritKey.reduce( +export function inherit(context: Context, inheritListeners: boolean): InheritContext { + const result = inheritKey.reduce( (obj, key) => { if (context.data[key]) { obj[mapInheritKey[key] || key] = context.data[key]; @@ -31,6 +31,13 @@ export function inherit(context: Context): InheritContext { }, {} as InheritContext ); + + if (inheritListeners) { + result.on = result.on || {}; + Object.assign(result.on, context.data.on); + } + + return result; } // emit event