com um clique
fix-modus-component-event-issues
// Debug and fix common event handling problems with Modus web components
// Debug and fix common event handling problems with Modus web components
Scaffold form components with proper Modus input integration, event handling, validation, and checkbox bug handling
Scaffold a new Modus wrapper component following established SolidJS patterns with proper TypeScript interfaces, event handling, and cleanup
Apply the critical checkbox value inversion workaround when working with ModusCheckbox components
Create Modus modals using the callback ref pattern for programmatic control
Help with correct Modus icon usage patterns including naming conventions, sizing, and accessibility
Build production-grade frontend interfaces using the Modus 2.0 Design System with Tailwind CSS. Use this skill when the user asks to build web components, pages, dashboards, or application screens. Enforces the 9-color semantic system, Modus Web Components, Modus Icons, and design system compliance. Framework-agnostic (works with SolidJS, React, Angular, or any framework).
| name | fix-modus-component-event-issues |
| description | Debug and fix common event handling problems with Modus web components |
Debug and fix common event handling problems with Modus web components in SolidJS.
Use this skill when:
Symptoms: Click handlers, change handlers, or other events don't fire.
Causes:
Solution:
// ✅ CORRECT: Proper event listener setup (SolidJS)
createEffect(() => {
const component = componentEl;
if (!component) return;
const handleEvent = (event: Event) => {
props.onEvent?.(event as CustomEvent<EventDetailType>);
};
if (props.onEvent) {
component.addEventListener("eventName", handleEvent);
}
return () => {
if (props.onEvent) {
component.removeEventListener("eventName", handleEvent);
}
};
});
Checklist:
let componentEl: HTMLModusWcComponentElement | undefined<modus-wc-component ref={(el) => (componentEl = el)} />createEffectSymptoms: Memory leaks, events firing multiple times, component errors after unmount.
Solution:
createEffect(() => {
const component = componentEl;
if (!component) return;
const handleEvent = (event: Event) => {
props.onEvent?.(event as CustomEvent<EventDetailType>);
};
component.addEventListener("eventName", handleEvent);
// ✅ CRITICAL: Always return cleanup function
return () => {
component.removeEventListener("eventName", handleEvent);
};
});
Symptoms: Events never fire, wrong event type received.
Common Event Names:
| Component | Event Name | Detail Type |
|---|---|---|
| Checkbox | inputChange | InputEvent |
| TextInput | inputChange | InputEvent |
| DropdownMenu | itemSelect | { value: string } |
| DropdownMenu | menuVisibilityChange | { isVisible: boolean } |
| Navbar | searchClick | MouseEvent | KeyboardEvent |
| Accordion | expandedChange | { expanded: boolean; index: number } |
Solution: Check Modus documentation for exact event names. They're case-sensitive.
Symptoms: Cannot read property 'addEventListener' of null, events don't attach.
Solution:
// ✅ CORRECT: Ref setup (SolidJS)
let componentEl: HTMLModusWcComponentElement | undefined;
createEffect(() => {
const component = componentEl;
if (!component) return; // ✅ Check before use
// Set up listeners
});
return (
<modus-wc-component ref={(el) => (componentEl = el)} /> // ✅ Callback ref
);
Symptoms: Can't access component properties, wrong value extracted.
Solution:
// ✅ CORRECT: Cast to proper element type
const handleInputChange = (event: Event) => {
const customEvent = event as CustomEvent<InputEvent>;
const value = (customEvent.target as HTMLModusWcTextInputElement).value;
props.onInputChange?.(value);
};
// ❌ WRONG: Don't use event.detail for input values
const handleInputChange = (event: Event) => {
const value = event.detail; // Wrong for input components!
};
Symptoms: Events fire multiple times, duplicate handlers.
Solution:
// ✅ CORRECT: Conditional attachment
if (props.onEvent) {
component.addEventListener("eventName", handleEvent);
}
// ✅ CORRECT: Remove in cleanup
return () => {
if (props.onEvent) {
component.removeEventListener("eventName", handleEvent);
}
};
When events aren't working, check:
Ref Setup
let ref is declared with correct typeif (!component) return)Event Listener Setup
createEffectCleanup
createEffectEvent Handling
CustomEvent typetarget.value vs detail)console.log(componentEl)target.value vs detailsrc/components/ModusCheckbox.tsx - Event handling examplesrc/components/ModusDropdownMenu.tsx - Multiple events examplesrc/components/ModusNavbar.tsx - Complex event handling