Skip to content

Conversation

@susnux
Copy link
Contributor

@susnux susnux commented Apr 20, 2025

☑️ Resolves

🏁 Checklist

  • ⛑️ Tests are included or are not applicable
  • 📘 Component documentation has been extended, updated or is not applicable
  • 2️⃣ Backport to stable8 for maintained Vue 2 version or not applicable

Signed-off-by: Ferdinand Thiessen <opensource@fthiessen.de>
@susnux susnux added 3. to review Waiting for reviews refactor ♻️ Pull request that is neither a fix nor a feature labels Apr 20, 2025
@susnux susnux requested a review from artonge May 6, 2025 13:06
@susnux susnux merged commit e2f7348 into main May 6, 2025
29 checks passed
@susnux susnux deleted the refactor/nc-chip-types branch May 6, 2025 14:36
/**
* The actions slot can be used to add custom actions (`NcAction*`) to the chips actions.
*/
actions: Slot
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Slot cannot be required

Suggested change
actions: Slot
actions?: Slot

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, slots?. doesn't make sense, when the type is : Slot, because Slot cannot be null/undefined.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

actions?: Slot

Why? Should be pretty fine according to the documentation: https://vuejs.org/api/sfc-script-setup#defineslots

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why?

Slot is () => VNode[] which cannot be undefined

It means that !!slots.actions is the same as true

Should be pretty fine according to the documentation: https://vuejs.org/api/sfc-script-setup#defineslots

Documentation is correct only for simple cases where slots object is never used, and when this type is only used for slot names and props.

It's probably done for simplicity or a possibility in the future to add slot content typing on compile-time.

Example:

const slots = defineSlots<{
  foo(): any
}>()

// inferred as "true"
// should be "boolean"
const hasFoo = !!slots.foo

// Throws "slots.foo is not a function" because slots are never required in Vue
// Should be warned by TS
// Inferred as any
// Should be VNode[]
const fooContent = slots.foo()

*/
emit('close')
}
default: Slot
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
default: Slot
default?: Slot

* Make sure that the icon is not exceeding a height of `--chip-size`.
* For round icons a exact size of `var(--chip-size)` is recommended.
*/
icon: Slot
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
icon: Slot
icon?: Slot

Comment on lines +190 to +191
const hasActions = () => Boolean(slots.actions?.())
const hasIcon = () => Boolean(props.iconPath || props.iconSvg || !!slots.icon?.())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The same as in previous components, we should not render slots several times, and we moved from default to icon slots in such cases to make it easy for component users to pass the slot dynamically. It is only a problem fo the default slot.

Suggested change
const hasActions = () => Boolean(slots.actions?.())
const hasIcon = () => Boolean(props.iconPath || props.iconSvg || !!slots.icon?.())
const hasActions = () => !!slots.actions
const hasIcon = () => Boolean(props.iconPath || props.iconSvg || !!slots.icon)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

3. to review Waiting for reviews refactor ♻️ Pull request that is neither a fix nor a feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants