diff --git a/services/web/frontend/js/features/source-editor/components/command-tooltip/href-tooltip.tsx b/services/web/frontend/js/features/source-editor/components/command-tooltip/href-tooltip.tsx index 6923b672f3..7fc42156d2 100644 --- a/services/web/frontend/js/features/source-editor/components/command-tooltip/href-tooltip.tsx +++ b/services/web/frontend/js/features/source-editor/components/command-tooltip/href-tooltip.tsx @@ -92,7 +92,7 @@ export const HrefTooltipContent: FC = () => { htmlSize={50} placeholder="https://…" value={url} - ref={element => { + ref={(element: HTMLInputElement) => { inputRef.current = element }} autoComplete="off" diff --git a/services/web/frontend/js/features/ui/components/bootstrap-5/form/form-control.tsx b/services/web/frontend/js/features/ui/components/bootstrap-5/form/form-control.tsx index 6458f5b40a..63618c3fad 100644 --- a/services/web/frontend/js/features/ui/components/bootstrap-5/form/form-control.tsx +++ b/services/web/frontend/js/features/ui/components/bootstrap-5/form/form-control.tsx @@ -1,16 +1,20 @@ -import { forwardRef } from 'react' +import React, { forwardRef } from 'react' import { Form, FormControlProps as BS5FormControlProps, } from 'react-bootstrap-5' import classnames from 'classnames' +import type { BsPrefixRefForwardingComponent } from 'react-bootstrap-5/helpers' -type FormControlProps = BS5FormControlProps & { +export type OLBS5FormControlProps = BS5FormControlProps & { prepend?: React.ReactNode append?: React.ReactNode } -const FormControl = forwardRef( +const FormControl: BsPrefixRefForwardingComponent< + 'input', + OLBS5FormControlProps +> = forwardRef( ({ prepend, append, className, ...props }, ref) => { if (prepend || append) { const wrapperClassNames = classnames('form-control-wrapper', { diff --git a/services/web/frontend/js/features/ui/components/ol/ol-form-control.tsx b/services/web/frontend/js/features/ui/components/ol/ol-form-control.tsx index 22d87d4551..290d48fa5d 100644 --- a/services/web/frontend/js/features/ui/components/ol/ol-form-control.tsx +++ b/services/web/frontend/js/features/ui/components/ol/ol-form-control.tsx @@ -1,12 +1,15 @@ import { forwardRef, ComponentProps, useCallback } from 'react' import { getAriaAndDataProps } from '@/features/utils/bootstrap-5' -import FormControl from '@/features/ui/components/bootstrap-5/form/form-control' +import FormControl, { + type OLBS5FormControlProps, +} from '@/features/ui/components/bootstrap-5/form/form-control' import BS3FormControl from '@/features/ui/components/bootstrap-3/form/form-control' import BootstrapVersionSwitcher from '@/features/ui/components/bootstrap-5/bootstrap-version-switcher' import OLSpinner from '@/features/ui/components/ol/ol-spinner' import Icon from '@/shared/components/icon' +import type { BsPrefixRefForwardingComponent } from 'react-bootstrap-5/helpers' -type OLFormControlProps = ComponentProps & { +type OLFormControlProps = OLBS5FormControlProps & { bs3Props?: Record 'data-ol-dirty'?: unknown 'main-field'?: any // For the CM6's benefit in the editor search panel @@ -17,77 +20,78 @@ type BS3FormControlProps = ComponentProps & { 'main-field'?: any } -const OLFormControl = forwardRef( - (props, ref) => { - const { bs3Props, append, ...rest } = props +const OLFormControl: BsPrefixRefForwardingComponent< + 'input', + OLFormControlProps +> = forwardRef((props, ref) => { + const { bs3Props, append, ...rest } = props - // Use a callback so that the ref passed to the BS3 FormControl is stable - const bs3InputRef = useCallback( - (inputElement: HTMLInputElement) => { - if (typeof ref === 'function') { - ref(inputElement) - } else if (ref) { - ref.current = inputElement - } - }, - [ref] - ) + // Use a callback so that the ref passed to the BS3 FormControl is stable + const bs3InputRef = useCallback( + (inputElement: HTMLInputElement) => { + if (typeof ref === 'function') { + ref(inputElement) + } else if (ref) { + ref.current = inputElement + } + }, + [ref] + ) - let bs3FormControlProps: BS3FormControlProps = { - inputRef: bs3InputRef, - componentClass: rest.as, - bsSize: rest.size, - id: rest.id, - name: rest.name, - className: rest.className, - style: rest.style, - type: rest.type, - value: rest.value, - defaultValue: rest.defaultValue, - required: rest.required, - disabled: rest.disabled, - placeholder: rest.placeholder, - readOnly: rest.readOnly, - autoComplete: rest.autoComplete, - autoFocus: rest.autoFocus, - minLength: rest.minLength, - maxLength: rest.maxLength, - onChange: rest.onChange as BS3FormControlProps['onChange'], - onKeyDown: rest.onKeyDown as BS3FormControlProps['onKeyDown'], - onFocus: rest.onFocus as BS3FormControlProps['onFocus'], - onBlur: rest.onBlur as BS3FormControlProps['onBlur'], - onInvalid: rest.onInvalid as BS3FormControlProps['onInvalid'], - prepend: rest.prepend, - size: rest.htmlSize, - 'main-field': rest['main-field'], - ...bs3Props, - } - - bs3FormControlProps = { - ...bs3FormControlProps, - ...getAriaAndDataProps(rest), - 'data-ol-dirty': rest['data-ol-dirty'], - } as typeof bs3FormControlProps & Record - - return ( - : append} - /> - } - bs5={ - : append} - /> - } - /> - ) + let bs3FormControlProps: BS3FormControlProps = { + inputRef: bs3InputRef, + componentClass: rest.as, + bsSize: rest.size, + id: rest.id, + name: rest.name, + className: rest.className, + style: rest.style, + type: rest.type, + value: rest.value, + defaultValue: rest.defaultValue, + required: rest.required, + disabled: rest.disabled, + placeholder: rest.placeholder, + readOnly: rest.readOnly, + autoComplete: rest.autoComplete, + autoFocus: rest.autoFocus, + minLength: rest.minLength, + maxLength: rest.maxLength, + onChange: rest.onChange as BS3FormControlProps['onChange'], + onKeyDown: rest.onKeyDown as BS3FormControlProps['onKeyDown'], + onFocus: rest.onFocus as BS3FormControlProps['onFocus'], + onBlur: rest.onBlur as BS3FormControlProps['onBlur'], + onInvalid: rest.onInvalid as BS3FormControlProps['onInvalid'], + prepend: rest.prepend, + size: rest.htmlSize, + 'main-field': rest['main-field'], + ...bs3Props, } -) + + bs3FormControlProps = { + ...bs3FormControlProps, + ...getAriaAndDataProps(rest), + 'data-ol-dirty': rest['data-ol-dirty'], + } as typeof bs3FormControlProps & Record + + return ( + : append} + /> + } + bs5={ + : append} + /> + } + /> + ) +}) OLFormControl.displayName = 'OLFormControl' export default OLFormControl