Skip to content

Commit

Permalink
Add elements getter
Browse files Browse the repository at this point in the history
  • Loading branch information
carry0987 committed Feb 7, 2024
1 parent 7272242 commit 21d0056
Showing 1 changed file with 18 additions and 10 deletions.
28 changes: 18 additions & 10 deletions src/radioBox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,24 @@ class RadioBox {
this.onChangeCallback = callback;
}

/**
* Get all radio box elements
* @return {RadioInputElement[]} All radio box elements
*/
public get elements(): RadioInputElement[] {
return this.allElement;
}

/**
* Get value of the checked radio box
* @return {string} Value of the checked radio box
*/
public get value(): string | null {
let checkedRadio = this.allElement.find(element => element.checked);

return checkedRadio ? checkedRadio.value : null;
}

public empty(): RadioBox {
this.allElement.forEach(element => {
element.checked = false;
Expand All @@ -185,16 +203,6 @@ class RadioBox {
instance.destroy();
}
}

/**
* Get value of the checked radio box
* @return {string} Value of the checked radio box
*/
public get value(): string | null {
let checkedRadio = this.allElement.find(element => element.checked);

return checkedRadio ? checkedRadio.value : null;
}
}

export default RadioBox;

0 comments on commit 21d0056

Please sign in to comment.