88 * @see Source https://github.com/chakra-ui/chakra-ui-vue/blob/master/packages/chakra-ui-core/src/CSwitch/CSwitch.js
99 */
1010
11- import { forwardProps , extractListeners } from '../utils'
11+ import { forwardProps } from '../utils'
1212
1313import CBox from '../CBox'
1414import CVisuallyHidden from '../CVisuallyHidden'
@@ -29,6 +29,15 @@ const switchSizes = {
2929 }
3030}
3131
32+ /** Emits events for functional components */
33+ const emitFunctionalEvent = ( fn , ...args ) => {
34+ if ( fn && typeof fn === 'function' ) {
35+ fn ( ...args )
36+ } else if ( Array . isArray ( fn ) ) {
37+ fn . forEach ( handler => typeof handler === 'function' && handler ( ...args ) )
38+ }
39+ }
40+
3241/**
3342 * CSwitch component
3443 *
@@ -101,18 +110,14 @@ const CSwitch = {
101110 }
102111 }
103112
104- // Events
105- const nonNativeEvents = {
113+ const eventListeners = {
114+ ... listeners ,
106115 change : ( e ) => {
107- const emitChange = listeners . change
108- if ( emitChange && typeof emitChange === 'function' ) {
109- emitChange ( ! props . isChecked )
110- }
116+ const newValue = ! props . isChecked
117+ emitFunctionalEvent ( listeners . change , newValue , e )
111118 }
112119 }
113120
114- const { native, nonNative } = extractListeners ( { listeners } , nonNativeEvents )
115-
116121 return h ( CBox , {
117122 ...rest ,
118123 props : {
@@ -142,8 +147,7 @@ const CSwitch = {
142147 checked : props . isChecked ,
143148 disabled : props . isDisabled
144149 } ,
145- on : nonNative ,
146- nativeOn : native
150+ on : eventListeners
147151 } ) ,
148152 h ( CControlBox , {
149153 attrs : styleProps
0 commit comments