Skip to content

Commit

Permalink
add forwardRef
Browse files Browse the repository at this point in the history
  • Loading branch information
joduplessis committed Jun 12, 2024
1 parent fa8808a commit b114432
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 8 deletions.
2 changes: 1 addition & 1 deletion packages/core/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@fold-dev/core",
"title": "Fold",
"version": "0.11.8",
"version": "0.12.0",
"description": "The UI library for product teams.",
"main": "dist/index.js",
"module": "dist/index.js",
Expand Down
5 changes: 4 additions & 1 deletion packages/core/src/contexts/fold.context.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,10 @@ export const FoldProvider = (props: any) => {
closeButton={dialog.closeButton}
title={dialog.title}
description={dialog.description}
onDismiss={() => setDialog({})}
onDismiss={(e) => {
if (dialog.onDismiss) dialog.onDismiss(e)
setDialog({})
}}
footer={dialog.footer}
header={dialog.header}
/>
Expand Down
4 changes: 3 additions & 1 deletion packages/core/src/dialog/dialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export type DialogOptions = {
footer?: any
header?: any
closeButton?: boolean
onDismiss?: (e) => void
portal?: any
}

Expand All @@ -25,7 +26,7 @@ export type DialogProps = {
header?: any
closeButton?: boolean
portal?: any
onDismiss?: any
onDismiss?: (e) => void
} & CommonProps

export const Dialog = (props: DialogProps) => {
Expand All @@ -43,6 +44,7 @@ export const Dialog = (props: DialogProps) => {
return (
<Modal
focusTrap
dismissOnEscape
role="dialog"
borderless
width={400}
Expand Down
10 changes: 5 additions & 5 deletions packages/core/src/modal/modal.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React, { ReactElement, useEffect, useRef } from 'react'
import React, { ReactElement, forwardRef, useEffect, useRef } from 'react'
import { ButtonProps, IconButton, View, useFocus, usePreventScrolling } from '../'
import { classNames, getActionClass, getKey } from '../helpers'
import { classNames, getActionClass, getKey, mergeRefs } from '../helpers'
import { CoreViewProps } from '../types'

export type ModalCloseProps = ButtonProps
Expand Down Expand Up @@ -46,7 +46,7 @@ export type ModalProps = {
onDismiss?: any
} & CoreViewProps

export const Modal = (props: ModalProps) => {
export const Modal = forwardRef((props: ModalProps, ref) => {
const {
headerProps = {},
footerProps = {},
Expand Down Expand Up @@ -118,7 +118,7 @@ export const Modal = (props: ModalProps) => {
aria-modal={true}
tabIndex={0}
onKeyDown={handleKeyDown}
ref={contentRef}>
ref={mergeRefs([contentRef, ref])}>
{header && <div className="f-modal__header f-row" {...headerProps}>{header}</div>}
{props.children && <div className="f-modal__body" {...bodyProps}>{props.children}</div>}
{footer && <div className="f-modal__footer f-row" {...footerProps}>{footer}</div>}
Expand All @@ -136,4 +136,4 @@ export const Modal = (props: ModalProps) => {
} else {
return null
}
}
})

0 comments on commit b114432

Please sign in to comment.