fix(radio-button): forward focus, blur events (#2135)

As identified in #2131, `focus` and `blur` events should be
forwarded to the underlying `RadioButton` element.
This commit is contained in:
Eric Liu 2025-03-22 13:02:28 -07:00 committed by GitHub
commit 1462e300d6
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 26 additions and 3 deletions

View file

@ -2966,6 +2966,8 @@ None.
| Event name | Type | Detail |
| :--------- | :-------- | :----- |
| focus | forwarded | -- |
| blur | forwarded | -- |
| change | forwarded | -- |
## `RadioButtonGroup`

View file

@ -11389,6 +11389,16 @@
}
],
"events": [
{
"type": "forwarded",
"name": "focus",
"element": "input"
},
{
"type": "forwarded",
"name": "blur",
"element": "input"
},
{
"type": "forwarded",
"name": "change",

View file

@ -71,6 +71,8 @@
required={$groupRequired ?? required}
{value}
class:bx--radio-button={true}
on:focus
on:blur
on:change
on:change={() => {
if (update) {

View file

@ -26,6 +26,12 @@
{id}
{name}
{ref}
on:focus={() => {
console.log("focus");
}}
on:blur={() => {
console.log("blur");
}}
on:change={() => {
console.log("change");
}}

View file

@ -91,8 +91,7 @@ describe("RadioButton", () => {
expect(consoleLog).toHaveBeenCalledWith("change");
});
// TODO(bug): forward focus/blur events.
it.skip("should handle focus and blur events", async () => {
it("should handle focus and blur events", async () => {
const consoleLog = vi.spyOn(console, "log");
render(RadioButton);

View file

@ -71,6 +71,10 @@ export type RadioButtonProps = Omit<$RestProps, keyof $Props> & $Props;
export default class RadioButton extends SvelteComponentTyped<
RadioButtonProps,
{ change: WindowEventMap["change"] },
{
focus: WindowEventMap["focus"];
blur: WindowEventMap["blur"];
change: WindowEventMap["change"];
},
{ labelText: {} }
> {}