detail property of CustomEvent.
Overview
This example shows a contact list where clicking a contact item sends the contact ID from the child component to the parent, which then displays the full contact details.Child Component: c-contact-list-item
The contact list item component dispatches an event containing the contact ID.JavaScript (contactListItem.js)
- The
detailproperty carries data from child to parent detailcan contain any serializable data (primitives, objects, arrays)- Receives contact data via
@api contactproperty
Template (contactListItem.html)
Parent Component: c-event-with-data
The parent component handles the event and extracts data fromevent.detail.
JavaScript (eventWithData.js)
- Access event data via
event.detail - The detail value is exactly what the child component provided
- Use the data to update parent component state
Template (eventWithData.html)
- Non-bubbling events require listeners on each child component
- Event handler
onselectbinds to the ‘select’ event - Parent displays selected contact details when a contact is chosen
CustomEvent Options
detail
Carries data from child to parent. Can be any type:Default Behavior
By default, custom events:- Do NOT bubble up the DOM tree (
bubbles: false) - Do NOT cross shadow DOM boundaries (
composed: false)
Event Flow
- User clicks a contact item
- Child component creates
CustomEventwith contact ID indetail - Child dispatches the event
- Parent’s
onselecthandler receives the event - Parent extracts
event.detailto get the contact ID - Parent finds and displays the full contact information
Source Files
- Child:
force-app/main/default/lwc/contactListItem/ - Parent:
force-app/main/default/lwc/eventWithData/
