Merged in feat/SW-3655-input-component (pull request #3296)
feat: (SW-3655) new Input and FormInput components * First version new Input and FormInput components * Handle aria-describedby with react-aria instead of manually add it * Update breaking unit and stories tests * Merge branch 'master' into feat/SW-3655-input-component * Update example form * Merge branch 'master' into feat/SW-3655-input-component * New lock file Approved-by: Linus Flood
This commit is contained in:
@@ -0,0 +1 @@
|
||||
export { mergeRefs } from './mergeRefs'
|
||||
@@ -0,0 +1,24 @@
|
||||
import type { Ref, RefCallback } from 'react'
|
||||
|
||||
/**
|
||||
* Merges multiple refs into a single ref callback.
|
||||
* Useful when you need to forward a ref while also using react-hook-form's field.ref.
|
||||
*
|
||||
* @example
|
||||
* ```tsx
|
||||
* <Input ref={mergeRefs(field.ref, forwardedRef)} />
|
||||
* ```
|
||||
*/
|
||||
export function mergeRefs<T>(
|
||||
...refs: Array<Ref<T> | undefined>
|
||||
): RefCallback<T> {
|
||||
return (node: T | null) => {
|
||||
refs.forEach((ref) => {
|
||||
if (typeof ref === 'function') {
|
||||
ref(node)
|
||||
} else if (ref) {
|
||||
ref.current = node
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user