1 import type { KeyboardEventHandler } from 'react';
3 import { c } from 'ttag';
5 import { useNotifications } from '@proton/components';
7 export const useMaxLengthLimiter = () => {
8 const { createNotification } = useNotifications();
12 originalOnKeyDown?: KeyboardEventHandler<HTMLInputElement | HTMLTextAreaElement>
13 ): KeyboardEventHandler<HTMLInputElement | HTMLTextAreaElement> =>
15 if (event.key.length === 1 && event.currentTarget.value.length >= maxLength) {
17 key: 'max-length-limiter',
20 text: c('Info').t`You have reached the maximum allowed length of ${maxLength} characters.`,
23 originalOnKeyDown?.(event);