Skip to content

Commit ed95a68

Browse files
yordan-stgjulivan
authored andcommitted
fix: improve accessibility and input handling
1 parent ae98da6 commit ed95a68

File tree

2 files changed

+24
-3
lines changed

2 files changed

+24
-3
lines changed

packages/pluggableWidgets/switch-web/src/__tests__/__snapshots__/Switch.spec.tsx.snap

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,18 @@ exports[`Switch with editable value renders the structure correctly 1`] = `
55
<div
66
class="widget-switch"
77
>
8+
<input
9+
aria-hidden="true"
10+
id="com.mendix.widgets.custom.switch1"
11+
style="opacity: 0; position: absolute; width: 1px; height: 1px;"
12+
tabindex="-1"
13+
type="checkbox"
14+
/>
815
<div
916
aria-checked="false"
1017
aria-labelledby="com.mendix.widgets.custom.switch1-label"
1118
aria-readonly="false"
1219
class="widget-switch-btn-wrapper widget-switch-btn-wrapper-default un-checked"
13-
id="com.mendix.widgets.custom.switch1"
1420
role="switch"
1521
tabindex="0"
1622
>
@@ -27,12 +33,19 @@ exports[`Switch with readonly value renders the structure correctly 1`] = `
2733
<div
2834
class="widget-switch"
2935
>
36+
<input
37+
aria-hidden="true"
38+
disabled=""
39+
id="com.mendix.widgets.custom.switch1"
40+
style="opacity: 0; position: absolute; width: 1px; height: 1px;"
41+
tabindex="-1"
42+
type="checkbox"
43+
/>
3044
<div
3145
aria-checked="false"
3246
aria-labelledby="com.mendix.widgets.custom.switch1-label"
3347
aria-readonly="true"
3448
class="widget-switch-btn-wrapper widget-switch-btn-wrapper-default disabled un-checked"
35-
id="com.mendix.widgets.custom.switch1"
3649
role="switch"
3750
tabindex="0"
3851
>

packages/pluggableWidgets/switch-web/src/components/Switch.tsx

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,16 @@ export interface SwitchProps extends Pick<SwitchContainerProps, "id" | "tabIndex
1414
export default function Switch(props: SwitchProps): ReactElement {
1515
return (
1616
<div className="widget-switch">
17-
<div
17+
<input
18+
type="checkbox"
1819
id={props.id}
20+
onClick={props.onClick}
21+
style={{ opacity: "0", position: "absolute", width: "1px", height: "1px" }}
22+
disabled={!props.editable}
23+
tabIndex={-1}
24+
aria-hidden="true"
25+
/>
26+
<div
1927
className={classNames("widget-switch-btn-wrapper", "widget-switch-btn-wrapper-default", {
2028
checked: props.isChecked,
2129
disabled: !props.editable,

0 commit comments

Comments
 (0)