Open akuu2510 opened 2 months ago
Probably this can be the fix
ADD THE BELOW LINE
if (this.getAllRadios().every(radio => radio.disabled)) return;
CODE
private handleKeyDown(event: KeyboardEvent) {
if (this.getAllRadios().every(radio => radio.disabled)) return;
if (!['ArrowUp', 'ArrowDown', 'ArrowLeft', 'ArrowRight', ' '].includes(event.key)) {
return;
}
const radios = this.getAllRadios().filter(radio => !radio.disabled);
const checkedRadio = radios.find(radio => radio.checked) ?? radios[0];
const incr = event.key === ' ' ? 0 : ['ArrowUp', 'ArrowLeft'].includes(event.key) ? -1 : 1;
const oldValue = this.value;
let index = radios.indexOf(checkedRadio) + incr;
if (index < 0) {
index = radios.length - 1;
}
if (index > radios.length - 1) {
index = 0;
}
this.getAllRadios().forEach(radio => {
radio.checked = false;
if (!this.hasButtonGroup) {
radio.tabIndex = -1;
}
});
this.value = radios[index].value;
radios[index].checked = true;
if (!this.hasButtonGroup) {
radios[index].tabIndex = 0;
radios[index].focus();
} else {
radios[index].shadowRoot!.querySelector('button')!.focus();
}
if (this.value !== oldValue) {
this.emit('sl-change');
this.emit('sl-input');
}
event.preventDefault();
}
That is when all the sl-radios are disabled then the up and down key board navigation should not work so in code I am returning it if all the radios are disabled @claviska can you please help me in this fix
Describe the bug
This bug is in the radio group component where all the sl-radios are disabled and then when I am using tab key from keyboard, disabled radio with value = true gets focussed and after I press up and down arrow keys the radio with value = true is getting un selected.
Expected behaviour
Component should not get focussed when disabled
To Reproduce
Steps to reproduce the behavior:
Demo
https://github.com/user-attachments/assets/03738d1d-0d09-499d-9d12-85d8f94b0844
Screenshots
Browser / OS