Skip to content

Commit 2225265

Browse files
AlanLesAlan Leszczuk
and
Alan Leszczuk
authored
feat: changes focusing invalid choices behavior in UiMultipleAnswer and UiMultipleChoices (#532)
* - adds emitted `focus:invalidChoice` event to UiMultipleAnswer and UiMultipleChoices; - adds `{ preventScroll: true }` to the `el.focus` call in the `focusElement` helper function; * fix: changes --font-weight-thick from 600 to 500 (MGPFE-2281) --------- Co-authored-by: Alan Leszczuk <[email protected]>
1 parent 0cf2b4b commit 2225265

File tree

4 files changed

+10
-4
lines changed

4 files changed

+10
-4
lines changed

src/components/organisms/UiMultipleAnswer/UiMultipleAnswer.vue

+5-1
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@ export type MultipleAnswerAttrsProps = DefineAttrsProps<MultipleAnswerProps>;
139139
export interface MultipleAnswerEmits {
140140
(e:'update:modelValue', value: MultipleAnswerModelValue): void;
141141
(e: 'update:invalid', value: boolean): void;
142+
(e: 'focus:invalidChoice', value: HTMLInputElement): void;
142143
}
143144
144145
const firstMultipleAnswerItemRef = ref<HTMLInputElement | null>(null);
@@ -212,7 +213,10 @@ watch([
212213
errorValue,
213214
item,
214215
]) => {
215-
if (errorValue) focusElement(item, true);
216+
if (errorValue && item) {
217+
focusElement(item, true);
218+
emit('focus:invalidChoice', item);
219+
}
216220
});
217221
</script>
218222

src/components/organisms/UiMultipleChoices/UiMultipleChoices.vue

+2
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ export type MultipleChoicesAttrsProps = DefineAttrsProps<MultipleChoicesProps>;
108108
export interface MultipleChoicesEmits {
109109
(e: 'update:modelValue', value: MultipleChoicesModelValue[]): void;
110110
(e: 'update:invalid', value: boolean): void;
111+
(e: 'focus:invalidChoice', value: HTMLInputElement): void;
111112
}
112113
export type InvalidInputs = Map<number, HTMLInputElement>;
113114
export type ExposedTypes = {
@@ -154,6 +155,7 @@ function focusInvalidChoice() {
154155
const elementToFocus = firstRadioItemsInput ?? firstInvalidChoice.$el.querySelector('input');
155156
156157
focusElement(elementToFocus, true);
158+
emit('focus:invalidChoice', elementToFocus);
157159
}
158160
159161
defineExpose<ExposedTypes>({ focusInvalidChoice });

src/styles/variables/typography.scss

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ html {
1515
--font-size-6: 1.75rem;
1616
--font-size-7: 2rem;
1717
--font-weight-default: 400;
18-
--font-weight-thick: 600;
18+
--font-weight-thick: 500;
1919
--letter-spacing-medium: 0.02em;
2020
--letter-spacing-none: 0;
2121
--letter-spacing-small: 0.01em;
@@ -61,4 +61,4 @@ html {
6161
--letter-spacing-h2: var(--letter-spacing-none);
6262
--letter-spacing-h3: var(--letter-spacing-none);
6363
}
64-
}
64+
}

src/utilities/helpers/focus-element/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ export const focusElement = (el: HTMLElement | null, focusVisible = false): Prom
66
}
77
return new Promise((resolve) => {
88
setTimeout(() => {
9-
el.focus();
9+
el.focus({ preventScroll: true });
1010
resolve();
1111
}, 0);
1212
});

0 commit comments

Comments
 (0)