Skip to content

Commit

Permalink
fix(react): makes dialogRef an optional prop for Dialog (#100)
Browse files Browse the repository at this point in the history
  • Loading branch information
schne324 authored Oct 26, 2020
1 parent 35dd790 commit b19190b
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
8 changes: 5 additions & 3 deletions packages/react/src/components/Dialog/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export interface DialogProps extends React.HTMLAttributes<HTMLDivElement> {
children: React.ReactNode;
className?: string;
show?: boolean;
dialogRef: React.Ref<HTMLDivElement>;
dialogRef?: React.Ref<HTMLDivElement>;
onClose: () => void;
forceAction?: boolean;
heading:
Expand All @@ -37,8 +37,7 @@ export default class Dialog extends React.Component<DialogProps, DialogState> {
static defaultProps = {
onClose: noop,
forceAction: false,
closeButtonText: 'Close',
dialogRef: noop
closeButtonText: 'Close'
};

static propTypes = {
Expand Down Expand Up @@ -135,6 +134,9 @@ export default class Dialog extends React.Component<DialogProps, DialogState> {
})}
ref={el => {
this.element = el;
if (!dialogRef) {
return;
}
setRef(dialogRef, el);
}}
{...other}
Expand Down
1 change: 1 addition & 0 deletions packages/react/src/utils/setRef.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export default function setRef<T>(ref: React.Ref<T>, element: T) {
if (typeof ref === 'function') {
ref(element);
} else {
// eslint-disable-next-line
// @ts-ignore
// we need to overwrite the existing value in some special cases
ref.current = element;
Expand Down

0 comments on commit b19190b

Please sign in to comment.