@mtes-mct/monitor-ui 6.5.0 → 6.5.1

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/CHANGELOG.md CHANGED
@@ -1,3 +1,10 @@
1
+ # [6.5.0](https://github.com/MTES-MCT/monitor-ui/compare/v6.4.1...v6.5.0) (2023-05-25)
2
+
3
+
4
+ ### Features
5
+
6
+ * **cypress:** extend retries to caught errors in fill command ([6ea6839](https://github.com/MTES-MCT/monitor-ui/commit/6ea6839c489b83c3807f5779ece254d9652dc95e))
7
+
1
8
  ## [6.4.1](https://github.com/MTES-MCT/monitor-ui/compare/v6.4.0...v6.4.1) (2023-05-25)
2
9
 
3
10
 
@@ -1,4 +1,4 @@
1
- import type { InputProps } from 'rsuite';
1
+ import { type InputProps } from 'rsuite';
2
2
  import type { Promisable } from 'type-fest';
3
3
  export type NumberInputProps = Omit<InputProps, 'as' | 'defaultValue' | 'id' | 'onChange' | 'type' | 'value'> & {
4
4
  error?: string | undefined;
@@ -11,4 +11,4 @@ export type NumberInputProps = Omit<InputProps, 'as' | 'defaultValue' | 'id' | '
11
11
  onChange?: ((nextValue: number | undefined) => Promisable<void>) | undefined;
12
12
  value?: number | undefined;
13
13
  };
14
- export declare function NumberInput({ className, error, isErrorMessageHidden, isLabelHidden, isLight, isUndefinedWhenDisabled, label, onChange, style, value, ...originalProps }: NumberInputProps): JSX.Element;
14
+ export declare function NumberInput({ className, error, isErrorMessageHidden, isLabelHidden, isLight, isUndefinedWhenDisabled, label, onBlur, onChange, onFocus, style, value, ...originalProps }: NumberInputProps): JSX.Element;
@@ -0,0 +1,2 @@
1
+ import { type RefObject } from 'react';
2
+ export declare function usePreventWheelEvent(inputRef: RefObject<HTMLInputElement | null>): (event: WheelEvent) => void;
package/index.js CHANGED
@@ -21309,26 +21309,58 @@ const Box$b = styled.div `
21309
21309
  }
21310
21310
  `;
21311
21311
 
21312
- function NumberInputWithRef({ isLight, max, min, onBack, onClick, onFilled, onFocus, onFormatError, onInput, onNext, onPrevious, size, value, ...nativeProps }, ref) {
21312
+ function usePreventWheelEvent(inputRef) {
21313
+ /**
21314
+ * Prevent any wheel event from emitting while allowing page scroll when focused.
21315
+ *
21316
+ * @description
21317
+ * We want to prevent the number input from changing when the user accidentally scrolls up or down.
21318
+ * That's why we prevent the default behavior of wheel events when it is focused.
21319
+ *
21320
+ * We also want to allow the user to be able to scroll the page while focused on a number input,
21321
+ * That's why we blur this input when a "wheel" (=> "scroll") event happens.
21322
+ *
21323
+ * Because React uses passive event handler by default,
21324
+ * we can't just call `preventDefault` in the `onWheel` event target.
21325
+ * We thus have to use the input reference and add our event handler manually.
21326
+ *
21327
+ * @see https://github.com/facebook/react/pull/19654
21328
+ */
21329
+ const preventWheelEvent = useCallback((event) => {
21330
+ if (!inputRef.current) {
21331
+ return;
21332
+ }
21333
+ event.preventDefault();
21334
+ inputRef.current.blur();
21335
+ },
21336
+ // We don't want to pass a reference as a hook dependency since it can't shallow-equal and `.current` is a pointer.
21337
+ // eslint-disable-next-line react-hooks/exhaustive-deps
21338
+ []);
21339
+ return preventWheelEvent;
21340
+ }
21341
+
21342
+ function NumberInputWithRef({ isLight, max, min, onBack, onBlur, onFilled, onFocus, onFormatError, onInput, onNext, onPrevious, size, value, ...nativeProps }, ref) {
21313
21343
  // eslint-disable-next-line no-null/no-null
21314
21344
  const inputRef = useRef(null);
21315
21345
  const placeholder = useMemo(() => '-'.repeat(size), [size]);
21316
21346
  useImperativeHandle(ref, () => inputRef.current);
21317
- const handleClick = useCallback((event) => {
21318
- // event.stopPropagation()
21319
- if (onClick) {
21320
- onClick(event);
21347
+ const preventWheelEvent = usePreventWheelEvent(inputRef);
21348
+ const handleBlur = useCallback((event) => {
21349
+ event.target.removeEventListener('wheel', preventWheelEvent);
21350
+ if (onBlur) {
21351
+ onBlur(event);
21321
21352
  }
21322
- }, [onClick]);
21353
+ }, [onBlur, preventWheelEvent]);
21323
21354
  const handleFocus = useCallback((event) => {
21324
21355
  if (!inputRef.current) {
21325
21356
  return;
21326
21357
  }
21358
+ event.target.addEventListener('wheel', preventWheelEvent);
21327
21359
  inputRef.current.select();
21328
21360
  if (onFocus) {
21329
21361
  onFocus(event);
21330
21362
  }
21331
- }, [onFocus]);
21363
+ }, [onFocus, preventWheelEvent]);
21332
21364
  const handleInput = useCallback(() => {
21333
21365
  if (!inputRef.current) {
21334
21366
  return;
@@ -21376,7 +21408,7 @@ function NumberInputWithRef({ isLight, max, min, onBack, onClick, onFilled, onFo
21376
21408
  onBack();
21377
21409
  }
21378
21410
  }, [onBack, onNext, onPrevious]);
21379
- return (jsx(StyledNumberInput, { ref: inputRef, "$isLight": isLight, "$size": size, defaultValue: value, maxLength: size, onClick: handleClick, onFocus: handleFocus, onInput: handleInput, onKeyDown: handleKeyDown, pattern: "\\d*", placeholder: placeholder, type: "text", ...nativeProps }, String(value)));
21411
+ return (jsx(StyledNumberInput, { ref: inputRef, "$isLight": isLight, "$size": size, defaultValue: value, maxLength: size, onBlur: handleBlur, onFocus: handleFocus, onInput: handleInput, onKeyDown: handleKeyDown, pattern: "\\d*", placeholder: placeholder, type: "text", ...nativeProps }, String(value)));
21380
21412
  }
21381
21413
  const NumberInput$1 = forwardRef(NumberInputWithRef);
21382
21414
  const StyledNumberInput = styled.input `
@@ -26015,11 +26047,14 @@ const Link = styled.a `
26015
26047
  }
26016
26048
  `;
26017
26049
 
26018
- function NumberInput({ className, error, isErrorMessageHidden = false, isLabelHidden = false, isLight = false, isUndefinedWhenDisabled = false, label, onChange, style, value, ...originalProps }) {
26050
+ function NumberInput({ className, error, isErrorMessageHidden = false, isLabelHidden = false, isLight = false, isUndefinedWhenDisabled = false, label, onBlur, onChange, onFocus, style, value, ...originalProps }) {
26051
+ // eslint-disable-next-line no-null/no-null
26052
+ const inputRef = useRef(null);
26019
26053
  const controlledClassname = useMemo(() => classnames('Field-NumberInput', className), [className]);
26020
26054
  const controlledError = useMemo(() => normalizeString(error), [error]);
26021
26055
  const hasError = useMemo(() => Boolean(controlledError), [controlledError]);
26022
26056
  const key = useKey([originalProps.disabled, originalProps.name]);
26057
+ const preventWheelEvent = usePreventWheelEvent(inputRef);
26023
26058
  const handleChange = useCallback((nextValue) => {
26024
26059
  if (!onChange) {
26025
26060
  return;
@@ -26029,8 +26064,20 @@ function NumberInput({ className, error, isErrorMessageHidden = false, isLabelHi
26029
26064
  const normalizedNextValue = !Number.isNaN(nextValueAsNumber) ? nextValueAsNumber : undefined;
26030
26065
  onChange(normalizedNextValue);
26031
26066
  }, [onChange]);
26067
+ const handleBlur = useCallback((event) => {
26068
+ event.target.removeEventListener('wheel', preventWheelEvent);
26069
+ if (onBlur) {
26070
+ onBlur(event);
26071
+ }
26072
+ }, [onBlur, preventWheelEvent]);
26073
+ const handleFocus = useCallback((event) => {
26074
+ event.target.addEventListener('wheel', preventWheelEvent);
26075
+ if (onFocus) {
26076
+ onFocus(event);
26077
+ }
26078
+ }, [onFocus, preventWheelEvent]);
26032
26079
  useFieldUndefineEffect(isUndefinedWhenDisabled && originalProps.disabled, onChange);
26033
- return (jsxs(Field$2, { className: controlledClassname, style: style, children: [jsx(Label, { disabled: originalProps.disabled, hasError: hasError, htmlFor: originalProps.name, isHidden: isLabelHidden, children: label }), jsx(StyledInput$2, { "$hasError": hasError, "$isLight": isLight, id: originalProps.name, onChange: handleChange, type: "number", value: value || '', ...originalProps }, key), !isErrorMessageHidden && hasError && jsx(FieldError, { children: controlledError })] }));
26080
+ return (jsxs(Field$2, { className: controlledClassname, style: style, children: [jsx(Label, { disabled: originalProps.disabled, hasError: hasError, htmlFor: originalProps.name, isHidden: isLabelHidden, children: label }), jsx(StyledInput$2, { ref: inputRef, "$hasError": hasError, "$isLight": isLight, id: originalProps.name, onBlur: handleBlur, onChange: handleChange, onFocus: handleFocus, type: "number", value: value || '', ...originalProps }, key), !isErrorMessageHidden && hasError && jsx(FieldError, { children: controlledError })] }));
26034
26081
  }
26035
26082
  const StyledInput$2 = styled(Input) `
26036
26083
  background-color: ${p => (p.$isLight ? p.theme.color.white : p.theme.color.gainsboro)};