Skip to content

Commit a120837

Browse files
authored
Revert "Try PageHeader, TextInput, Tooltip"
This reverts commit 07eeee3.
1 parent 07eeee3 commit a120837

3 files changed

Lines changed: 16 additions & 17 deletions

File tree

packages/react/src/PageHeader/PageHeader.tsx

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, {useEffect} from 'react'
1+
import React, {useEffect, useRef} from 'react'
22
import type {ResponsiveValue} from '../hooks/useResponsiveValue'
33
import {isResponsiveValue} from '../hooks/useResponsiveValue'
44
import Heading from '../Heading'
@@ -10,7 +10,7 @@ import {getResponsiveAttributes} from '../internal/utils/getResponsiveAttributes
1010
import type {ForwardRefComponent as PolymorphicForwardRefComponent} from '../utils/polymorphic'
1111
import {areAllValuesTheSame, haveRegularAndWideSameValue} from '../utils/getBreakpointDeclarations'
1212
import {warning} from '../utils/warning'
13-
import {useProvidedRefOrCreate} from '../hooks'
13+
import {useMergedRefs} from '../hooks'
1414
import type {AriaRole, FCWithSlotMarker} from '../utils/types'
1515
import {clsx} from 'clsx'
1616

@@ -49,7 +49,8 @@ export type PageHeaderProps = {
4949

5050
const Root = React.forwardRef<HTMLDivElement, React.PropsWithChildren<PageHeaderProps>>(
5151
({children, className, as: BaseComponent = 'div', 'aria-label': ariaLabel, role, hasBorder}, forwardedRef) => {
52-
const rootRef = useProvidedRefOrCreate<HTMLDivElement>(forwardedRef as React.RefObject<HTMLDivElement>)
52+
const rootRef = useRef<HTMLDivElement>(null)
53+
const mergedRef = useMergedRefs(rootRef, forwardedRef)
5354

5455
const isInteractive = (element: HTMLElement) => {
5556
return (
@@ -105,7 +106,7 @@ const Root = React.forwardRef<HTMLDivElement, React.PropsWithChildren<PageHeader
105106

106107
return (
107108
<BaseComponent
108-
ref={rootRef}
109+
ref={mergedRef}
109110
className={clsx(classes.PageHeader, className)}
110111
data-has-border={hasBorder ? 'true' : undefined}
111112
aria-label={ariaLabel}
@@ -205,12 +206,10 @@ export type TitleAreaProps = {
205206

206207
const TitleArea = React.forwardRef<HTMLDivElement, React.PropsWithChildren<TitleAreaProps>>(
207208
({children, className, hidden = false, variant = 'medium'}, forwardedRef) => {
208-
const titleAreaRef = useProvidedRefOrCreate<HTMLDivElement>(forwardedRef as React.RefObject<HTMLDivElement>)
209209
return (
210210
<div
211211
className={clsx(classes.TitleArea, className)}
212-
// @ts-expect-error it needs a non nullable ref
213-
ref={titleAreaRef}
212+
ref={forwardedRef}
214213
data-component="TitleArea"
215214
{...getResponsiveAttributes('size-variant', variant)}
216215
{...getHiddenDataAttributes(hidden)}

packages/react/src/TextInput/TextInput.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import {AlertFillIcon} from '@primer/octicons-react'
77

88
import classes from './TextInput.module.css'
99
import TextInputInnerVisualSlot from '../internal/components/TextInputInnerVisualSlot'
10-
import {useProvidedRefOrCreate} from '../hooks'
1110
import type {Merge} from '../utils/types'
1211
import type {StyledWrapperProps} from '../internal/components/TextInputWrapper'
1312
import TextInputWrapper from '../internal/components/TextInputWrapper'
@@ -16,6 +15,7 @@ import UnstyledTextInput from '../internal/components/UnstyledTextInput'
1615
import VisuallyHidden from '../_VisuallyHidden'
1716
import {CharacterCounter} from '../utils/character-counter'
1817
import Text from '../Text'
18+
import {useMergedRefs} from '../hooks'
1919

2020
export type TextInputNonPassthroughProps = {
2121
/** @deprecated Use `leadingVisual` or `trailingVisual` prop instead */
@@ -103,7 +103,8 @@ const TextInput = React.forwardRef<HTMLInputElement, TextInputProps>(
103103
ref,
104104
) => {
105105
const [isInputFocused, setIsInputFocused] = useState<boolean>(false)
106-
const inputRef = useProvidedRefOrCreate(ref as React.RefObject<HTMLInputElement | null>)
106+
const inputRef = useRef<HTMLInputElement>(null)
107+
const mergedRef = useMergedRefs(inputRef, ref)
107108
const [characterCount, setCharacterCount] = useState<string>('')
108109
const [isOverLimit, setIsOverLimit] = useState<boolean>(false)
109110
const [screenReaderMessage, setScreenReaderMessage] = useState<string>('')
@@ -258,8 +259,7 @@ const TextInput = React.forwardRef<HTMLInputElement, TextInputProps>(
258259
{typeof LeadingVisual !== 'string' && isValidElementType(LeadingVisual) ? <LeadingVisual /> : LeadingVisual}
259260
</TextInputInnerVisualSlot>
260261
<UnstyledTextInput
261-
// @ts-expect-error it needs a non nullable ref
262-
ref={inputRef}
262+
ref={mergedRef}
263263
disabled={disabled}
264264
onFocus={handleInputFocus}
265265
onBlur={handleInputBlur}

packages/react/src/TooltipV2/Tooltip.tsx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import React, {Children, useEffect, useRef, useState, useMemo, type ForwardRefExoticComponent} from 'react'
2-
import {useId, useProvidedRefOrCreate, useOnEscapePress, useIsMacOS} from '../hooks'
1+
import React, {Children, useEffect, useState, useMemo, type ForwardRefExoticComponent, useRef} from 'react'
2+
import {useId, useOnEscapePress, useIsMacOS, useMergedRefs} from '../hooks'
33
import {invariant} from '../utils/invariant'
44
import {warning} from '../utils/warning'
55
import {getAnchoredPosition} from '@primer/behaviors'
@@ -50,7 +50,7 @@ type TriggerPropsType = Pick<
5050
| 'onTouchCancel'
5151
| 'onTouchEnd'
5252
> & {
53-
ref?: React.RefObject<HTMLElement>
53+
ref?: React.Ref<HTMLElement>
5454
}
5555

5656
// map tooltip direction to anchoredPosition props
@@ -126,7 +126,8 @@ export const Tooltip: ForwardRefExoticComponent<
126126
) => {
127127
const tooltipId = useId(id)
128128
const child = Children.only(children)
129-
const triggerRef = useProvidedRefOrCreate(forwardedRef as React.RefObject<HTMLElement>)
129+
const triggerRef = useRef<HTMLElement>(null)
130+
const mergedTriggerRef = useMergedRefs(triggerRef, forwardedRef)
130131
const tooltipElRef = useRef<HTMLDivElement>(null)
131132

132133
const [calculatedDirection, setCalculatedDirection] = useState<TooltipDirection>(direction)
@@ -284,8 +285,7 @@ export const Tooltip: ForwardRefExoticComponent<
284285
{React.isValidElement(child) &&
285286
// eslint-disable-next-line react-hooks/refs
286287
React.cloneElement(child as React.ReactElement<TriggerPropsType>, {
287-
// @ts-expect-error it needs a non nullable ref
288-
ref: triggerRef,
288+
ref: mergedTriggerRef,
289289
// If it is a type description, we use tooltip to describe the trigger
290290
'aria-describedby': (() => {
291291
// If tooltip is not a description type, keep the original aria-describedby

0 commit comments

Comments
 (0)