fix: fix field select options positions after option removal (#5350)

- Adds an util `toSpliced`. We cannot used the native Javascript
`Array.prototype.toSpliced` method as Chromatic servers don't support
it.
- Makes sure Select field options have sequential positions after
removing an option (form validation schema checks that positions are
sequential and considers options invalid otherwise).
This commit is contained in:
Thaïs
2024-05-10 18:31:22 +02:00
committed by GitHub
parent 72521d5554
commit 0fb416d17c
5 changed files with 99 additions and 16 deletions

View File

@ -8,6 +8,7 @@ import {
} from '@/ui/utilities/pointer-event/hooks/useListenClickOutsideV2';
import { ClickOutsideListenerCallback } from '@/ui/utilities/pointer-event/types/ClickOutsideListenerCallback';
import { getScopeIdFromComponentId } from '@/ui/utilities/recoil-scope/utils/getScopeIdFromComponentId';
import { toSpliced } from '~/utils/array/toSpliced';
import { isDefined } from '~/utils/isDefined';
export const useClickOutsideListener = (componentId: string) => {
@ -117,8 +118,11 @@ export const useClickOutsideListener = (componentId: string) => {
const callbackToUnsubscribeIsFound = indexOfCallbackToUnsubscribe > -1;
if (callbackToUnsubscribeIsFound) {
const newCallbacksWithoutCallbackToUnsubscribe =
existingCallbacks.toSpliced(indexOfCallbackToUnsubscribe, 1);
const newCallbacksWithoutCallbackToUnsubscribe = toSpliced(
existingCallbacks,
indexOfCallbackToUnsubscribe,
1,
);
set(
getClickOutsideListenerCallbacksState,