Skip to content

Commit bc726a9

Browse files
authored
fix(ui5-radio-button): correct keyboard navigation in RTL (#5529)
Fixes: #5165
1 parent 62c4c20 commit bc726a9

File tree

3 files changed

+41
-2
lines changed

3 files changed

+41
-2
lines changed

packages/main/src/RadioButton.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -400,11 +400,13 @@ class RadioButton extends UI5Element {
400400
return this.toggle();
401401
}
402402

403-
if (isDown(event) || isRight(event)) {
403+
const isRTL = this.effectiveDir === "rtl";
404+
405+
if (isDown(event) || (!isRTL && isRight(event)) || (isRTL && isLeft(event))) {
404406
this._handleDown(event);
405407
}
406408

407-
if (isUp(event) || isLeft(event)) {
409+
if (isUp(event) || (!isRTL && isLeft(event)) || (isRTL && isRight(event))) {
408410
this._handleUp(event);
409411
}
410412
}

packages/main/test/pages/RadioButton.html

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,13 @@
121121
<ui5-label>- for belize use 'sap-ui-theme=sap_belize'</ui5-label>
122122
</p>
123123

124+
<ui5-title level="H2">Navigation in RTL</ui5-title><br>
125+
<div dir="rtl">
126+
<ui5-radio-button id="rtlOptionA" name="rtlGroup" text="Option A" checked></ui5-radio-button>
127+
<ui5-radio-button id="rtlOptionB" name="rtlGroup" text="Option B"></ui5-radio-button>
128+
<ui5-radio-button id="rtlOptionC" name="rtlGroup" text="Option C"></ui5-radio-button>
129+
</div>
130+
124131
<script>
125132
var counter = 0;
126133
var groupEventCounter = 0;

packages/main/test/specs/RadioButton.spec.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,3 +182,33 @@ describe("RadioButton general interaction", () => {
182182
assert.strictEqual(await rb.getProperty("ariaLabelText"), `${labelText} ${rbText}`, "The ariaLabelText includes both the accessibleNameRef text and the radio button text.");
183183
});
184184
});
185+
186+
describe("RadioButton keyboard handling in RTL", () => {
187+
before(async () => {
188+
await browser.url(`test/pages/RadioButton.html`);
189+
});
190+
191+
it("Arrow Left", async () => {
192+
const rb = await browser.$("#rtlOptionA");
193+
await rb.click();
194+
await rb.keys("ArrowLeft");
195+
196+
assert.ok(await browser.$("#rtlOptionB").getAttribute("checked"), "Pressing ArrowLeft selects the next radio in the group.");
197+
198+
await browser.$("#rtlOptionB").keys("ArrowLeft");
199+
200+
assert.ok(await browser.$("#rtlOptionC").getAttribute("checked"), "Pressing ArrowLeft selects the next radio in the group.");
201+
});
202+
203+
it("Arrow Right", async () => {
204+
const rb = await browser.$("#rtlOptionA");
205+
await rb.click();
206+
await rb.keys("ArrowRight");
207+
208+
assert.ok(await browser.$("#rtlOptionC").getAttribute("checked"), "Pressing ArrowRight selects the next radio in the group.");
209+
210+
await browser.$("#rtlOptionC").keys("ArrowRight");
211+
212+
assert.ok(await browser.$("#rtlOptionB").getAttribute("checked"), "Pressing ArrowRight selects the next radio in the group.");
213+
});
214+
});

0 commit comments

Comments
 (0)