From e7ef05adaf816f53ee9d8122353c2bfe510a036c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bronislav=20Jord=C3=A1n?= <58697105+brojor@users.noreply.github.com> Date: Fri, 9 Sep 2022 13:28:17 +0200 Subject: [PATCH] fix(base-input): preserve attrs & slots reactivity (#4) Co-authored-by: JD Solanki --- .../src/components/base-input/ABaseInput.tsx | 41 +++++++++---------- 1 file changed, 20 insertions(+), 21 deletions(-) diff --git a/packages/anu-vue/src/components/base-input/ABaseInput.tsx b/packages/anu-vue/src/components/base-input/ABaseInput.tsx index b3426569..8a514ceb 100644 --- a/packages/anu-vue/src/components/base-input/ABaseInput.tsx +++ b/packages/anu-vue/src/components/base-input/ABaseInput.tsx @@ -19,9 +19,10 @@ export const ABaseInput = defineComponent({ disabled, readonly, }, - setup(props, { slots, attrs, expose }) { + setup(props, ctx) { + const { expose } = ctx const iconTransition = 'transition duration-150 ease -in' - const elementId = attrs.id || props.label ? `a-input-${attrs.id || props.label}` : undefined + const elementId = ctx.attrs.id || props.label ? `a-input-${ctx.attrs.id || props.label}` : undefined const refRoot = ref() const refInputContainer = ref() @@ -30,15 +31,13 @@ export const ABaseInput = defineComponent({ refInputContainer, }) - const { class: rootClasses, ...inputAttrs } = attrs - // TODO(Enhancement): We might need to remove absolute added to html input element to retain width instead of providing min-w to below wrapper // TODO: We need to improve default slot implementation so that we can provide selected slot to selection component - return () =>
+ return () =>
{/* 👉 Label */} { - slots.label - ? slots.label?.() + ctx.slots.label + ? ctx.slots.label?.() : props.label ? : null @@ -47,8 +46,8 @@ export const ABaseInput = defineComponent({
{/* 👉 Slot: Prepend */} { - slots.prepend - ? slots.prepend?.() + ctx.slots.prepend + ? ctx.slots.prepend?.() : props.prependIcon ? : null @@ -63,28 +62,28 @@ export const ABaseInput = defineComponent({ {/* 👉 Slot: Prepend Inner */} { - slots['prepend-inner'] - ? slots['prepend-inner']?.() + ctx.slots['prepend-inner'] + ? ctx.slots['prepend-inner']?.() : props.prependInnerIcon ? : null } {/* 👉 Slot: Default */} - {slots.default?.({ + {ctx.slots.default?.({ + ...ctx.attrs, class: [ 'a-base-input-child w-full h-full absolute inset-0 rounded-inherit', - slots['prepend-inner'] || props.prependInnerIcon ? 'a-base-input-w-prepend-inner' : 'a-base-input-wo-prepend-inner', - slots['append-inner'] || props.appendInnerIcon ? 'a-base-input-w-append-inner' : 'a-base-input-wo-append-inner', + ctx.slots['prepend-inner'] || props.prependInnerIcon ? 'a-base-input-w-prepend-inner' : 'a-base-input-wo-prepend-inner', + ctx.slots['append-inner'] || props.appendInnerIcon ? 'a-base-input-w-append-inner' : 'a-base-input-wo-append-inner', ], - ...inputAttrs, id: elementId, })} {/* 👉 Slot: Append Inner */} { - slots['append-inner'] - ? slots['append-inner']?.() + ctx.slots['append-inner'] + ? ctx.slots['append-inner']?.() : props.appendInnerIcon ? : null @@ -94,8 +93,8 @@ export const ABaseInput = defineComponent({ {/* 👉 Slot: Append */} { - slots.append - ? slots.append?.() + ctx.slots.append + ? ctx.slots.append?.() : props.appendIcon ? : null @@ -103,8 +102,8 @@ export const ABaseInput = defineComponent({
{/* 👉 Slot: Bottom */} { - slots.bottom - ? slots.bottom?.() + ctx.slots.bottom + ? ctx.slots.bottom?.() :
{props.error || props.hint}