{"size": 624, "ext": "js", "max_stars_repo_path": "packages/dom-state-handler/src/states/radioGroup.js", "max_stars_repo_name": "Goldinteractive/gold-features", "max_stars_repo_stars_event_min_datetime": "2018-02-19T10:03:12.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-07T19:14:49.000Z", "max_issues_repo_path": "packages/dom-state-handler/src/states/radioGroup.js", "max_issues_repo_name": "Goldinteractive/gold-features", "max_issues_repo_issues_event_min_datetime": "2018-10-17T17:14:34.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-26T20:43:51.000Z", "max_forks_repo_path": "packages/dom-state-handler/src/states/radioGroup.js", "max_forks_repo_name": "Goldinteractive/gold-features", "max_forks_repo_forks_event_min_datetime": "2018-04-27T12:55:29.000Z", "max_forks_repo_forks_event_max_datetime": "2019-11-28T12:58:30.000Z"}
{"max_stars_count": 9, "max_issues_count": 17, "max_forks_count": 2, "avg_line_length": 27.1304347826, "max_line_length": 80, "alphanum_fraction": 0.6682692308}
import StateHandler from './'

export default class RadioGroup extends StateHandler {
  static isHandledBy(node) {
    return node.dataset && node.dataset.stateHandlerType === 'radio-group'
  }

  getName() {
    return this.node.querySelector('input[type="radio"]').name
  }

  getValue() {
    const selectedRadio = this.node.querySelector('input[type="radio"]:checked')
    return selectedRadio ? selectedRadio.value : undefined
  }
  setValue(value) {
    const $$radios = [...this.node.querySelectorAll('input[type="radio"]')]
    $$radios.forEach($radio => {
      $radio.checked = $radio.value === value
    })
  }
}
