@@ -30,12 +30,10 @@ const filteredDropdownOptions = (selectionModel, filter, selectorPrefix) => {
3030 * Display a given option
3131 *
3232 * @param {SelectionOption } option the option to display
33- * @param {boolean } checked the current state of the option
34- * @param {function } onChange function called with the option and its new state when the option's state change
3533 * @param {string } [selectorPrefix] prefix used to generate DOM selectors for the component
3634 * @return {Component } the option's view
3735 */
38- const displayOption = ( option , checked , onChange , selectorPrefix ) => {
36+ const displayOption = ( option , selectorPrefix ) => {
3937 const selector = option . selector ?? option . value ;
4038
4139 return h (
@@ -47,8 +45,8 @@ const filteredDropdownOptions = (selectionModel, filter, selectorPrefix) => {
4745 {
4846 type : selectionModel . multiple || selectionModel . allowEmpty ? 'checkbox' : 'radio' ,
4947 name : `${ selectorPrefix } dropdown-option-${ selectionModel . multiple ? selector : 'group' } ` ,
50- checked,
51- onchange : ( e ) => onChange ( option , e . target . checked ) ,
48+ checked : selectionModel . isSelected ( option ) ,
49+ onchange : ( e ) => e . target . checked ? selectionModel . select ( option ) : selectionModel . deselect ( option ) ,
5250 } ,
5351 ) ,
5452 option . label || option . value ,
@@ -60,28 +58,20 @@ const filteredDropdownOptions = (selectionModel, filter, selectorPrefix) => {
6058 * Displays the list of available options
6159 *
6260 * @param {SelectionOption[] } availableOptions the list of all the available options
63- * @param {function } onChange callback to handle an option state change
6461 * @return {Component } the options list
6562 */
66- const optionsList = ( availableOptions , onChange ) => {
63+ const optionsList = ( availableOptions ) => {
6764 if ( availableOptions . length === 0 ) {
6865 return h ( '.ph2.pv1' , h ( 'em' , 'No options' ) ) ;
6966 }
7067
7168 return availableOptions . map ( ( option ) => displayOption (
7269 option ,
73- selectionModel . isSelected ( option ) ,
74- onChange ,
7570 selectorPrefix ,
7671 ) ) ;
7772 } ;
7873
79- return h ( '.dropdown-options' , optionsList (
80- filterSelectionOptions ( selectionModel . options , filter ) ,
81- ( option , state ) => {
82- state ? selectionModel . select ( option ) : selectionModel . deselect ( option ) ;
83- } ,
84- ) ) ;
74+ return h ( '.dropdown-options' , optionsList ( filterSelectionOptions ( selectionModel . options , filter ) ) ) ;
8575} ;
8676
8777/**
0 commit comments