@entur/form 10.3.0 → 10.3.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/form.cjs +114 -112
- package/dist/form.cjs.map +1 -1
- package/dist/form.mjs +115 -113
- package/dist/form.mjs.map +1 -1
- package/dist/styles.css +9 -1
- package/dist/styles.no-base-tokens.css +1 -1
- package/package.json +11 -10
package/dist/form.cjs
CHANGED
|
@@ -137,9 +137,9 @@ const InputGroupLabel = ({
|
|
|
137
137
|
const VariantContext = React.createContext(null);
|
|
138
138
|
const VariantProvider = ({
|
|
139
139
|
children,
|
|
140
|
-
variant
|
|
140
|
+
variant
|
|
141
141
|
}) => {
|
|
142
|
-
return /* @__PURE__ */ jsxRuntime.jsx(VariantContext.Provider, { value: variant, children });
|
|
142
|
+
return /* @__PURE__ */ jsxRuntime.jsx(VariantContext.Provider, { value: variant ?? null, children });
|
|
143
143
|
};
|
|
144
144
|
const useVariant = () => {
|
|
145
145
|
const context = React.useContext(VariantContext);
|
|
@@ -1133,120 +1133,122 @@ const getLastWithDataValue = (parent) => {
|
|
|
1133
1133
|
return null;
|
|
1134
1134
|
};
|
|
1135
1135
|
const defaultElement = "button";
|
|
1136
|
-
const SegmentedChoice =
|
|
1137
|
-
|
|
1138
|
-
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
|
|
1149
|
-
|
|
1150
|
-
|
|
1151
|
-
|
|
1152
|
-
|
|
1153
|
-
|
|
1154
|
-
|
|
1155
|
-
|
|
1156
|
-
|
|
1157
|
-
|
|
1158
|
-
|
|
1159
|
-
|
|
1160
|
-
|
|
1161
|
-
|
|
1162
|
-
|
|
1163
|
-
const handleKeyDown = (e) => {
|
|
1164
|
-
const current = e.currentTarget;
|
|
1165
|
-
const focusChoice = (el) => {
|
|
1166
|
-
if (!el) return;
|
|
1167
|
-
el.focus();
|
|
1168
|
-
setFocusedValue(el.getAttribute("data-value") || null);
|
|
1136
|
+
const SegmentedChoice = utils.forwardRefPolymorphic(
|
|
1137
|
+
function SegmentedChoice2({
|
|
1138
|
+
children,
|
|
1139
|
+
className,
|
|
1140
|
+
style,
|
|
1141
|
+
value,
|
|
1142
|
+
as,
|
|
1143
|
+
onChange,
|
|
1144
|
+
"data-first-child": isFirstChild,
|
|
1145
|
+
...rest
|
|
1146
|
+
}, ref) {
|
|
1147
|
+
const Element = as || defaultElement;
|
|
1148
|
+
const {
|
|
1149
|
+
value: selectedValue,
|
|
1150
|
+
onChange: contextOnChange,
|
|
1151
|
+
size,
|
|
1152
|
+
focusedValue,
|
|
1153
|
+
setFocusedValue
|
|
1154
|
+
} = useSegmentedContext();
|
|
1155
|
+
const isChecked = selectedValue === value;
|
|
1156
|
+
const tabIndex = React.useMemo(() => {
|
|
1157
|
+
if (selectedValue !== null) return isChecked ? 0 : -1;
|
|
1158
|
+
return isFirstChild ? 0 : -1;
|
|
1159
|
+
}, [isChecked, selectedValue, isFirstChild]);
|
|
1160
|
+
const handleSelection = () => {
|
|
1161
|
+
contextOnChange(value);
|
|
1162
|
+
onChange?.(value);
|
|
1169
1163
|
};
|
|
1170
|
-
|
|
1171
|
-
|
|
1172
|
-
|
|
1173
|
-
|
|
1174
|
-
|
|
1175
|
-
|
|
1176
|
-
}
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
|
|
1186
|
-
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
|
|
1198
|
-
|
|
1199
|
-
|
|
1200
|
-
|
|
1201
|
-
|
|
1202
|
-
|
|
1203
|
-
|
|
1164
|
+
const handleKeyDown = (e) => {
|
|
1165
|
+
const current = e.currentTarget;
|
|
1166
|
+
const focusChoice = (el) => {
|
|
1167
|
+
if (!el) return;
|
|
1168
|
+
el.focus();
|
|
1169
|
+
setFocusedValue(el.getAttribute("data-value") || null);
|
|
1170
|
+
};
|
|
1171
|
+
switch (e.key) {
|
|
1172
|
+
case "ArrowLeft":
|
|
1173
|
+
case "ArrowUp": {
|
|
1174
|
+
e.preventDefault();
|
|
1175
|
+
focusChoice(getPrevWithDataValue(current));
|
|
1176
|
+
break;
|
|
1177
|
+
}
|
|
1178
|
+
case "ArrowRight":
|
|
1179
|
+
case "ArrowDown": {
|
|
1180
|
+
e.preventDefault();
|
|
1181
|
+
focusChoice(getNextWithDataValue(current));
|
|
1182
|
+
break;
|
|
1183
|
+
}
|
|
1184
|
+
case "Home": {
|
|
1185
|
+
e.preventDefault();
|
|
1186
|
+
const parent = current.parentElement;
|
|
1187
|
+
focusChoice(getFirstWithDataValue(parent));
|
|
1188
|
+
break;
|
|
1189
|
+
}
|
|
1190
|
+
case "End": {
|
|
1191
|
+
e.preventDefault();
|
|
1192
|
+
const parent = current.parentElement;
|
|
1193
|
+
focusChoice(getLastWithDataValue(parent));
|
|
1194
|
+
break;
|
|
1195
|
+
}
|
|
1196
|
+
case " ":
|
|
1197
|
+
e.preventDefault();
|
|
1198
|
+
if (as === "a") {
|
|
1199
|
+
handleSelection();
|
|
1200
|
+
const linkElement = e.currentTarget;
|
|
1201
|
+
if (linkElement.href) {
|
|
1202
|
+
queueMicrotask(() => {
|
|
1203
|
+
linkElement.click();
|
|
1204
|
+
});
|
|
1205
|
+
}
|
|
1206
|
+
} else {
|
|
1207
|
+
handleSelection();
|
|
1204
1208
|
}
|
|
1205
|
-
|
|
1209
|
+
break;
|
|
1210
|
+
case "Enter":
|
|
1206
1211
|
handleSelection();
|
|
1207
|
-
|
|
1208
|
-
|
|
1209
|
-
|
|
1210
|
-
|
|
1211
|
-
|
|
1212
|
-
|
|
1213
|
-
|
|
1212
|
+
break;
|
|
1213
|
+
case "Escape":
|
|
1214
|
+
e.preventDefault();
|
|
1215
|
+
setFocusedValue(null);
|
|
1216
|
+
break;
|
|
1217
|
+
}
|
|
1218
|
+
};
|
|
1219
|
+
const onFocus = React.useCallback(() => {
|
|
1220
|
+
setFocusedValue(value);
|
|
1221
|
+
}, [setFocusedValue, value]);
|
|
1222
|
+
const onBlur = React.useCallback(() => {
|
|
1223
|
+
if (focusedValue === value) {
|
|
1214
1224
|
setFocusedValue(null);
|
|
1215
|
-
|
|
1216
|
-
}
|
|
1217
|
-
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
|
|
1222
|
-
|
|
1223
|
-
|
|
1224
|
-
|
|
1225
|
-
|
|
1226
|
-
|
|
1227
|
-
|
|
1228
|
-
|
|
1229
|
-
|
|
1230
|
-
|
|
1231
|
-
|
|
1232
|
-
|
|
1233
|
-
|
|
1234
|
-
|
|
1235
|
-
|
|
1236
|
-
|
|
1237
|
-
|
|
1238
|
-
|
|
1239
|
-
|
|
1240
|
-
|
|
1241
|
-
|
|
1242
|
-
onBlur,
|
|
1243
|
-
role: "radio",
|
|
1244
|
-
// For defaultElement button we override type submit
|
|
1245
|
-
...as === void 0 && { type: "button" },
|
|
1246
|
-
...rest
|
|
1247
|
-
};
|
|
1248
|
-
return /* @__PURE__ */ jsxRuntime.jsx(Element, { ...elementProps, children });
|
|
1249
|
-
});
|
|
1225
|
+
}
|
|
1226
|
+
}, [focusedValue, value, setFocusedValue]);
|
|
1227
|
+
const elementProps = {
|
|
1228
|
+
className: classNames(
|
|
1229
|
+
"eds-segmented-choice",
|
|
1230
|
+
{
|
|
1231
|
+
"eds-segmented-choice--large": size === "large"
|
|
1232
|
+
},
|
|
1233
|
+
className
|
|
1234
|
+
),
|
|
1235
|
+
style,
|
|
1236
|
+
"aria-checked": isChecked,
|
|
1237
|
+
"data-value": value,
|
|
1238
|
+
ref,
|
|
1239
|
+
tabIndex,
|
|
1240
|
+
onClick: handleSelection,
|
|
1241
|
+
onKeyDown: handleKeyDown,
|
|
1242
|
+
onFocus,
|
|
1243
|
+
onBlur,
|
|
1244
|
+
role: "radio",
|
|
1245
|
+
// For defaultElement button we override type submit
|
|
1246
|
+
...as === void 0 && { type: "button" },
|
|
1247
|
+
...rest
|
|
1248
|
+
};
|
|
1249
|
+
return /* @__PURE__ */ jsxRuntime.jsx(Element, { ...elementProps, children });
|
|
1250
|
+
}
|
|
1251
|
+
);
|
|
1250
1252
|
const SegmentedControlComponent = Object.assign(
|
|
1251
1253
|
SegmentedControl,
|
|
1252
1254
|
{
|