Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: various react errors in console #639

Merged
merged 2 commits into from
Sep 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 3 additions & 6 deletions src/components/Breadcrumbs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -406,6 +406,7 @@ export function Breadcrumbs({
}: BreadcrumbsProps & NavProps) {
const contextCrumbs = useContext(BreadcrumbsContext)?.breadcrumbs
const breadcrumbs = propsCrumbs || contextCrumbs
const nodeRef = useRef<HTMLDivElement>()

if (!breadcrumbs) {
throw Error(
Expand All @@ -430,15 +431,11 @@ export function Breadcrumbs({
<Transition
key={String(transitionKey.current)}
timeout={200}
// Typing for 'addEndListener' on <Transition> component is incorrect
// when not providing 'ref' prop
// @ts-expect-error
addEndListener={(node, done) => {
node?.addEventListener('refitdone', done, false)
}}
nodeRef={nodeRef}
>
{(state) => (
<DynamicBreadcrumbs
wrapperRef={nodeRef}
minLength={minLength}
maxLength={maxLength}
collapsible={collapsible}
Expand Down
27 changes: 9 additions & 18 deletions src/components/Modal.tsx
Original file line number Diff line number Diff line change
@@ -1,29 +1,25 @@
// this is just styling, actual modal logic is in ModalWrapper

import {
type ReactNode,
type Ref,
forwardRef,
useCallback,
useEffect,
} from 'react'
import { type ReactNode, type Ref, forwardRef, useCallback } from 'react'

import styled, {
type StyledComponentPropsWithRef,
useTheme,
} from 'styled-components'

import { type ColorKey, type Nullable, type SeverityExt } from '../types'
import { VisuallyHidden } from 'react-aria'

import * as Dialog from '@radix-ui/react-dialog'

import useLockedBody from '../hooks/useLockedBody'
import { type ColorKey, type Nullable, type SeverityExt } from '../types'

import Card from './Card'
import CheckRoundedIcon from './icons/CheckRoundedIcon'
import type createIcon from './icons/createIcon'
import ErrorIcon from './icons/ErrorIcon'
import InfoIcon from './icons/InfoIcon'
import WarningIcon from './icons/WarningIcon'
import { ModalWrapper, type ModalWrapperProps } from './ModalWrapper'
import Card from './Card'

export const SEVERITIES = [
'info',
Expand All @@ -45,7 +41,6 @@ type ModalPropsType = ModalWrapperProps & {
header?: ReactNode
actions?: ReactNode
severity?: ModalSeverity
lockBody?: boolean
asForm?: boolean
formProps?: StyledComponentPropsWithRef<'form'>
}
Expand Down Expand Up @@ -147,7 +142,6 @@ function ModalRef(
size = form ? 'large' : 'medium',
onClose,
severity,
lockBody = true,
asForm = false,
formProps = {},
scrollable = true,
Expand All @@ -159,12 +153,6 @@ function ModalRef(
const HeaderIcon = severityToIcon[severity ?? 'default']
const iconColorKey = severityToIconColorKey[severity ?? 'default']

const [, setBodyLocked] = useLockedBody(open && lockBody)

useEffect(() => {
setBodyLocked(lockBody && open)
}, [lockBody, open, setBodyLocked])

const triggerClose = useCallback(
(open: boolean) => {
if (!open) onClose?.()
Expand Down Expand Up @@ -195,6 +183,9 @@ function ModalRef(
$scrollable={scrollable}
$hasActions={!!actions}
>
<VisuallyHidden>
<Dialog.Title>{header}</Dialog.Title>
</VisuallyHidden>
{!!header && (
<ModalHeaderWrapSC ref={ref}>
{HeaderIcon && (
Expand Down
24 changes: 14 additions & 10 deletions src/components/SidebarItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,21 @@ type SidebarItemProps = ComponentProps<typeof ItemSC> & {
active?: boolean
}

function SidebarItemRef({
children,
tooltip = '',
expandedLabel = '',
className,
...props
}: SidebarItemProps) {
function SidebarItemRef(
{
children,
tooltip = '',
expandedLabel = '',
className,
...props
}: SidebarItemProps,
ref: Ref<HTMLDivElement>
) {
const { isExpanded } = useSidebar()

return (
<WithTooltip
ref={ref}
tooltip={tooltip}
className={className}
{...props}
Expand All @@ -35,7 +39,7 @@ function SidebarItemRef({

function WithTooltipRef(
{ children, clickable, tooltip = '', ...props }: SidebarItemProps,
ref: Ref<any>
ref: Ref<HTMLDivElement>
) {
const { layout, isExpanded } = useSidebar()

Expand Down Expand Up @@ -117,18 +121,18 @@ const ItemSC = styled.div<{

function ItemRef(
{ children, clickable = false, active = false, ...props }: SidebarItemProps,
ref: Ref<any>
ref: Ref<HTMLDivElement>
) {
const { layout, variant } = useSidebar()
const isHorizontal = layout === 'horizontal'

return (
<ItemSC
ref={ref}
$clickable={clickable}
$active={active}
$isHorizontal={isHorizontal}
$variant={variant}
ref={ref}
{...props}
>
{children}
Expand Down
2 changes: 2 additions & 0 deletions src/components/Tooltip.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ function Tooltip({
const {
x,
y,
refs,
reference,
floating,
strategy: finalStrategy,
Expand Down Expand Up @@ -197,6 +198,7 @@ function Tooltip({
}
>
<CSSTransition
nodeRef={refs.floating}
in={isOpen}
appear
timeout={250}
Expand Down
Loading