Skip to content

Commit

Permalink
feat: add ref to modal
Browse files Browse the repository at this point in the history
  • Loading branch information
illiteratewriter committed Mar 8, 2023
1 parent fc539c9 commit 8f5e219
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 12 deletions.
8 changes: 4 additions & 4 deletions src/ModalBody.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from 'react';
import React, { forwardRef } from 'react';
import PropTypes from 'prop-types';
import classNames from 'classnames';
import { mapToCssModules, tagPropType } from './utils';
Expand All @@ -15,15 +15,15 @@ const defaultProps = {
tag: 'div',
};

function ModalBody(props) {
const ModalBody = forwardRef((props, ref) => {
const { className, cssModule, tag: Tag, ...attributes } = props;
const classes = mapToCssModules(
classNames(className, 'modal-body'),
cssModule,
);

return <Tag {...attributes} className={classes} />;
}
return <Tag {...attributes} className={classes} ref={ref} />;
});

ModalBody.propTypes = propTypes;
ModalBody.defaultProps = defaultProps;
Expand Down
8 changes: 4 additions & 4 deletions src/ModalFooter.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from 'react';
import React, { forwardRef } from 'react';
import PropTypes from 'prop-types';
import classNames from 'classnames';
import { mapToCssModules, tagPropType } from './utils';
Expand All @@ -16,15 +16,15 @@ const defaultProps = {
tag: 'div',
};

function ModalFooter(props) {
const ModalFooter = forwardRef((props, ref) => {
const { className, cssModule, tag: Tag, ...attributes } = props;
const classes = mapToCssModules(
classNames(className, 'modal-footer'),
cssModule,
);

return <Tag {...attributes} className={classes} />;
}
return <Tag {...attributes} className={classes} ref={ref} />;
});

ModalFooter.propTypes = propTypes;
ModalFooter.defaultProps = defaultProps;
Expand Down
8 changes: 4 additions & 4 deletions src/ModalHeader.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from 'react';
import React, { forwardRef } from 'react';
import PropTypes from 'prop-types';
import classNames from 'classnames';
import { mapToCssModules, tagPropType } from './utils';
Expand All @@ -25,7 +25,7 @@ const defaultProps = {
closeAriaLabel: 'Close',
};

function ModalHeader(props) {
const ModalHeader = forwardRef((props, ref) => {
let closeButton;
const {
className,
Expand Down Expand Up @@ -56,14 +56,14 @@ function ModalHeader(props) {
}

return (
<WrapTag {...attributes} className={classes}>
<WrapTag {...attributes} className={classes} ref={ref}>
<Tag className={mapToCssModules('modal-title', cssModule)}>
{children}
</Tag>
{close || closeButton}
</WrapTag>
);
}
});

ModalHeader.propTypes = propTypes;
ModalHeader.defaultProps = defaultProps;
Expand Down

0 comments on commit 8f5e219

Please sign in to comment.