File tree Expand file tree Collapse file tree 1 file changed +23
-0
lines changed Expand file tree Collapse file tree 1 file changed +23
-0
lines changed Original file line number Diff line number Diff line change 1+ import type { FieldElement } from 'skyroc-type-utils' ;
2+
3+ import { isEventObject } from './object' ;
4+
5+ type Event = { target : any } ;
6+
7+ export const isCheckBoxInput = ( element : FieldElement ) : element is HTMLInputElement => element . type === 'checkbox' ;
8+
9+ export const isRadioInput = ( element : FieldElement ) : element is HTMLInputElement => element . type === 'radio' ;
10+
11+ export const isFileInput = ( element : FieldElement ) : element is HTMLInputElement => element . type === 'file' ;
12+
13+ export const getEventValue = ( event : unknown , valuePropName : string = 'value' ) => {
14+ if ( ! isEventObject ( event ) ) return event ;
15+
16+ const { target } = event as Event ;
17+
18+ if ( ! target ) return event ;
19+
20+ if ( isCheckBoxInput ( target ) ) return target . checked ;
21+
22+ return target [ valuePropName ] ;
23+ } ;
You can’t perform that action at this time.
0 commit comments