Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(ui5-checkbox): improved key down behavior for readonly state #8226

Merged
merged 4 commits into from
Feb 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions packages/main/src/CheckBox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -321,13 +321,17 @@ class CheckBox extends UI5Element implements IFormElement {
_onkeydown(e: KeyboardEvent) {
if (isSpace(e)) {
e.preventDefault();
this.active = true;
}

if (this.readonly || this.disabled) {
return;
}

if (isEnter(e)) {
this.toggle();
this.active = true;
}

this.active = true;
}

_onkeyup(e: KeyboardEvent) {
Expand Down
4 changes: 2 additions & 2 deletions packages/main/test/pages/CheckBox.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@

<body class="checkbox1auto">
<ui5-checkbox text="Option"></ui5-checkbox>
<ui5-checkbox id="cbError" readonly text="Option"></ui5-checkbox>
<ui5-checkbox id="cbError" disabled text="Option"></ui5-checkbox>
<ui5-checkbox id="cbReadonly" readonly text="Option"></ui5-checkbox>
<ui5-checkbox id="cbDisabled" disabled text="Option"></ui5-checkbox>
<ui5-checkbox id="cbError" value-state="Error" text="Option"></ui5-checkbox>
<ui5-checkbox id="truncatingCb" text="Long long long text that should truncate at some point" class="checkbox2auto"></ui5-checkbox>
<ui5-checkbox text="Long long long text that should truncate at some point"></ui5-checkbox>
Expand Down
30 changes: 30 additions & 0 deletions packages/main/test/specs/CheckBox.spec.js
plamenivanov91 marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
import { assert } from "chai";
const KEYS = {
ENTER: '\uE007',
SPACE: '\ue00D',
}

describe("CheckBox general interaction", () => {
before(async () => {
Expand All @@ -22,6 +26,32 @@ describe("CheckBox general interaction", () => {
assert.strictEqual(await field.getProperty("value"), "3", "Change event should be fired 3 times");
});

it("tests readonly space and enter keys active state", async () => {
const checkBox = await browser.$("#cbReadonly");

await checkBox.click(); // force focus

// Setup for SPACE Key
await browser.performActions([{
type: 'key',
id: 'keyboard3',
actions: [{ type: 'keyDown', value: KEYS.SPACE }],
}]);
// Action
assert.strictEqual(await checkBox.getAttribute("active"), null, "Space doesn't trigger active attr");
await browser.releaseActions();

// Setup for ENTER Key
await browser.performActions([{
type: 'key',
id: 'keyboard3',
actions: [{ type: 'keyDown', value: KEYS.ENTER }],
}]);
// Action
assert.strictEqual(await checkBox.getAttribute("active"), null, "Enter doesn't trigger active attr");
await browser.releaseActions();
});

it("tests change event not fired, when disabled", async () => {
const checkBox = await browser.$("#cb2");
const field = await browser.$("#field");
Expand Down