Skip to content

Commit d14f49c

Browse files
committed
chore: radio check event added
1 parent 23b7d0b commit d14f49c

File tree

2 files changed

+16
-7
lines changed

2 files changed

+16
-7
lines changed

elements/pf-radio/demo/pf-radio.html

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
<section class='container'>
22
<p> Select a title </p>
33
<div class='radio-group'>
4-
<pf-radio id="title-mr" label="Mr" name="title" checked=${false}></pf-radio>
5-
<pf-radio id="title-miss" label="Miss" name="title" checked=${false}></pf-radio>
6-
<pf-radio id="title-mrs" label="Mrs" name="title" checked=${false}></pf-radio>
7-
<pf-radio id="title-ms" label="Ms" name="title" checked=${false}></pf-radio>
8-
<pf-radio id="title-dr" label="Dr" name="title" checked=${false}></pf-radio>
9-
<pf-radio id="title-other" label="Other" name="title" checked=${false}></pf-radio>
4+
<pf-radio id="title-mr" value='mr' label="Mr" name="title" checked=${false}></pf-radio>
5+
<pf-radio id="title-miss" value='miss' label="Miss" name="title" checked=${false}></pf-radio>
6+
<pf-radio id="title-mrs" value='mrs' label="Mrs" name="title" checked=${false}></pf-radio>
7+
<pf-radio id="title-ms" value='ms' label="Ms" name="title" checked=${false}></pf-radio>
8+
<pf-radio id="title-dr" value='dr' label="Dr" name="title" checked=${false}></pf-radio>
9+
<pf-radio id="title-other" value='other' label="Other" name="title" checked=${false}></pf-radio>
1010
</div>
1111
<pf-button> Submit</pf-button>
1212
</section>

elements/pf-radio/pf-radio.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,12 @@ import { customElement } from 'lit/decorators/custom-element.js';
33
import styles from './pf-radio.css';
44
import { property } from 'lit/decorators/property.js';
55

6+
export class PfRadioChangeEvent extends Event {
7+
constructor(public event: Event, public value: string) {
8+
super('change', { bubbles: true });
9+
}
10+
}
11+
612
/**
713
* Radio
814
* @slot - Place element content here
@@ -52,7 +58,7 @@ export class PfRadio extends LitElement {
5258
document.addEventListener('keydown', this.#onKeyPress);
5359
}
5460

55-
#onRadioButtonClick() {
61+
#onRadioButtonClick(event: Event) {
5662
if (!this.checked) {
5763
const root: Node = this.getRootNode();
5864
let radioGroup: NodeListOf<PfRadio>;
@@ -65,6 +71,7 @@ export class PfRadio extends LitElement {
6571
});
6672
this.checked = true;
6773
this.tabIndex = 0;
74+
this.dispatchEvent(new PfRadioChangeEvent(event, this.value));
6875
}
6976
}
7077
}
@@ -118,6 +125,7 @@ export class PfRadio extends LitElement {
118125
const nextIndex: number = (index + direction + radioGroup.length) % radioGroup.length;
119126
radioGroup[nextIndex].focus();
120127
radioGroup[nextIndex].checked = true;
128+
this.dispatchEvent(new PfRadioChangeEvent(event, radioGroup[nextIndex].value));
121129
}
122130
});
123131
}
@@ -131,6 +139,7 @@ export class PfRadio extends LitElement {
131139
id=${this.id}
132140
.name=${this.name}
133141
type='radio'
142+
value=${this.value}
134143
tabindex=${this.tabIndex}
135144
.checked=${this.checked}
136145
/>

0 commit comments

Comments
 (0)