Mixins / Authoring components

Common pitfalls when authoring components

  • State rule beaten by a variant: A rule in variants overrides components; put state styles (aria-selected) inside each variant that sets the same property.
  • Shorthand resetting a longhand: Writing background in a hover rule clears background-clip from the base; use matching longhands across base and states.
  • Two Mounts on one element: Foldkit keeps one OnMount per element; pass mounts through Slots so the resolver composes them, or place a custom mount on its own element.
  • Mount reading stale inputs: Mounts run on element creation and removal; use a Command or key the element when an effect depends on changing Model fields.
  • Rapid keypresses outrunning frames: Carry needed context in Message or read document.activeElement at press time, and call Frames.track().settle() in tests.
  • Markup outside Slots: Bare elements cannot be styled or checked from outside; render through Slots with CSS custom properties or data attributes for structural hints.
  • No-op returning { ...model }: Returning a fresh object triggers unnecessary renders; return the exact model reference on no-ops.
  • Native disabled vs. aria-disabled: Native disabled drops focus and Enter submission; use aria-disabled on buttons and enforce disabled checks in update.
  • Two Slots on one element: Placing two slots.*.attrs(...) calls on one element overwrites Class; give each Slot its own element.

Next