Custom event listeners
Attach any custom event listeners to specific nodes in your component, or to the entire component itself.
Custom event handlers
Use the eventHandlers prop to register any JavaScript functions that should fire based on any event you care about. Mason offers two methods - you can target the entire component or you can target specific elements within the component.
Targeting the entire component:
Provide an eventHandlers
prop to your component as an object that contains all of the custom event handler functions you want to register on your component.
Register functions on the events you care about, with the syntax:
For example:
Targeting specific elements within your component:
Provide an eventHandlers
prop to your component as an object that contains all of the custom event handler functions you want to register on your component.
Register functions on the events and nodes you care about, with the syntax:
You define the LabelName in the builder. For example, if you had a button named "login button", the onClick event listener syntax would be onLoginButtonClick.
For example:
Supported event listeners
JavaScript event
Mason Syntax
onClick / onLabelNameClick
onDoubleClick / onLabelNameDoubleClick
onMouseDown / onLabelNameMouseDown
onMouseUp / onLabelNameMouseUp
onMouseOut / onLabelNameMouseOut
onMouseLeave / onLabelNameMouseLeave
onMouseEnter / onLabelNameMouseEnter
onMouseOver / onLabelNameMouseOver
onKeyDown / onLabelNameKeyDown
onKeyUp / onLabelNameKeyUp
onFocus / onLabelNameFocus
onBlur / onLabelNameBlur
Live demo
See a working demo of all supported event listeners at https://showcase.trymason.com/events
Last updated