Question presented to candidate:
"Someone wrote <BaseButton class="primary" aria-label="Save" @click="save" />, but BaseButton only declares a label prop. Where do class, aria-label and the click listener end up, and what changes if the component has two root elements or sets inheritAttrs: false?"
What a strong answer should cover:
- Fallthrough attributes are everything the parent passes that the child does not declare as a prop or an emitted event:
class,style,id,aria-*,data-*, andv-onlisteners (asonClickand so on). - With a single root element, Vue adds them to that root automatically;
classandstyleare merged with the root's own, other attributes override. - Declared props and declared emits are removed from
$attrs; undeclared listeners become native listeners on the root, which can make a handler fire twice if the child also emits that event. - With multiple roots (a fragment) Vue cannot choose, warns "Extraneous non-props attributes...", and you must bind
v-bind="$attrs"on the right element. inheritAttrs: falseturns off the automatic behaviour so you can place$attrson an inner element, such as the<input>inside a label wrapper.- If the root is another component, the attributes keep falling through to that component.
Clarifying questions expected:
- "Does
BaseButtonemit its ownclickevent, or is it relying on the native one?" - "Is the root element the right target, or should attributes reach an inner element?"
Code / implementation expected: Optional β a wrapper component with inheritAttrs: false and v-bind="$attrs" on the inner element.