Update selected item color in Pass menu
[ProtonMail-WebClient.git] / packages / pass / hooks / useMaxLengthLimiter.ts
blobf42a8f06953868ca7aca4e4638f81402f1f406f5
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();
10     return (
11             maxLength: number,
12             originalOnKeyDown?: KeyboardEventHandler<HTMLInputElement | HTMLTextAreaElement>
13         ): KeyboardEventHandler<HTMLInputElement | HTMLTextAreaElement> =>
14         (event) => {
15             if (event.key.length === 1 && event.currentTarget.value.length >= maxLength) {
16                 createNotification({
17                     key: 'max-length-limiter',
18                     type: 'warning',
19                     deduplicate: true,
20                     text: c('Info').t`You have reached the maximum allowed length of ${maxLength} characters.`,
21                 });
22             }
23             originalOnKeyDown?.(event);
24         };