Repository URL to install this package:
Version:
0.9.5 ▾
|
import { isSelectedInput } from './isSelectedInput'
// unselectInputsListFor
// unselectInputsListExcept
function unselectInputsList(input, inputsList) {
// console.log('unselectInputsList', inputsList, input)
// filter + set
//
// compare an input
// if (it isn't the one that just changed)
// -> unselect it
const unSelectOtherInputs = selectedInput => {
// console.log('unSelectOtherInputs', selectedInput)
const isDiffIdentifier = selectedInput.identifier !== input.identifier
// console.log({ isDiffIdentifier })
if (isDiffIdentifier) {
// console.warn('UNSELECTING')
// selectedInput.isSelected = false
if (selectedInput.unselect) {
// console.log('selecting input')
selectedInput.unselect()
} else {
throw new TypeError('use the action')
}
// selectedInput.isSelected = !selectedInput.isSelected
}
}
// if some are selected, unselect the others
if (inputsList.some(isSelectedInput)) {
// @todo may need slice?
// console.warn('OTHERS_ARE_SELECTED')
//
const selectedList = inputsList.filter(isSelectedInput)
selectedList.forEach(unSelectOtherInputs)
}
}
unselectInputsList.isRadioUnSelect = true
export { unselectInputsList }
export default unselectInputsList