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

Feat(bs5) change .close to .btn close #2116

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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 2 additions & 4 deletions src/Alert.js
Expand Up @@ -59,7 +59,7 @@ function Alert(props) {
{ 'alert-dismissible': toggle }
), cssModule);

const closeClasses = mapToCssModules(classNames('close', closeClassName), cssModule);
const closeClasses = mapToCssModules(classNames('btn-close', closeClassName), cssModule);

const alertTransition = {
...Fade.defaultProps,
Expand All @@ -71,9 +71,7 @@ function Alert(props) {
return (
<Fade {...attributes} {...alertTransition} tag={Tag} className={classes} in={isOpen} role="alert" innerRef={innerRef}>
{toggle ?
<button type="button" className={closeClasses} aria-label={closeAriaLabel} onClick={toggle}>
<span aria-hidden="true">&times;</span>
</button>
<button type="button" className={closeClasses} aria-label={closeAriaLabel} onClick={toggle} />
: null}
{children}
</Fade>
Expand Down
2 changes: 1 addition & 1 deletion src/Button.js
Expand Up @@ -67,7 +67,7 @@ class Button extends React.Component {

const classes = mapToCssModules(classNames(
className,
{ close },
close && 'btn-close',
close || 'btn',
close || btnOutlineColor,
size ? `btn-${size}` : false,
Expand Down
8 changes: 1 addition & 7 deletions src/ModalHeader.js
Expand Up @@ -11,15 +11,13 @@ const propTypes = {
cssModule: PropTypes.object,
children: PropTypes.node,
closeAriaLabel: PropTypes.string,
charCode: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
close: PropTypes.object,
};

const defaultProps = {
tag: 'h5',
wrapTag: 'div',
closeAriaLabel: 'Close',
charCode: 215,
};

const ModalHeader = (props) => {
Expand All @@ -32,7 +30,6 @@ const ModalHeader = (props) => {
tag: Tag,
wrapTag: WrapTag,
closeAriaLabel,
charCode,
close,
...attributes } = props;

Expand All @@ -42,11 +39,8 @@ const ModalHeader = (props) => {
), cssModule);

if (!close && toggle) {
const closeIcon = typeof charCode === 'number' ? String.fromCharCode(charCode) : charCode;
closeButton = (
<button type="button" onClick={toggle} className={mapToCssModules('close', cssModule)} aria-label={closeAriaLabel}>
<span aria-hidden="true">{closeIcon}</span>
</button>
<button type="button" onClick={toggle} className={mapToCssModules('btn-close', cssModule)} aria-label={closeAriaLabel} />
);
}

Expand Down
6 changes: 1 addition & 5 deletions src/ToastHeader.js
Expand Up @@ -35,7 +35,6 @@ const ToastHeader = (props) => {
tag: Tag,
wrapTag: WrapTag,
closeAriaLabel,
charCode,
close,
tagClassName,
icon: iconProp,
Expand All @@ -47,11 +46,8 @@ const ToastHeader = (props) => {
), cssModule);

if (!close && toggle) {
const closeIcon = typeof charCode === 'number' ? String.fromCharCode(charCode) : charCode;
closeButton = (
<button type="button" onClick={toggle} className={mapToCssModules('close', cssModule)} aria-label={closeAriaLabel}>
<span aria-hidden="true">{closeIcon}</span>
</button>
<button type="button" onClick={toggle} className={mapToCssModules('btn-close', cssModule)} aria-label={closeAriaLabel} />
);
}

Expand Down
2 changes: 1 addition & 1 deletion src/__tests__/Alert.spec.js
Expand Up @@ -16,7 +16,7 @@ describe('Alert', () => {
it('should pass close className down', () => {
function noop() { }
const alert = mount(<Alert toggle={noop} closeClassName="test-class-name">Yo!</Alert>);
expect(alert.find('.close').hostNodes().prop('className')).toContain('test-class-name');
expect(alert.find('.btn-close').hostNodes().prop('className')).toContain('test-class-name');
});

it('should pass other props down', () => {
Expand Down
2 changes: 1 addition & 1 deletion src/__tests__/Button.spec.js
Expand Up @@ -104,7 +104,7 @@ describe('Button', () => {
const wrapper = shallow(<Button close />);
const actualInnerHTML = wrapper.children().html();

expect(wrapper.find('.close').length).toBe(1);
expect(wrapper.find('.btn-close').length).toBe(1);
expect(wrapper.find('.btn').length).toBe(0);
expect(wrapper.find('.btn-secondary').length).toBe(0);
expect(wrapper.find('button').prop('aria-label')).toMatch(/close/i);
Expand Down
24 changes: 1 addition & 23 deletions src/__tests__/ModalHeader.spec.js
Expand Up @@ -22,7 +22,7 @@ describe('ModalHeader', () => {

expect(wrapper.hasClass('other')).toBe(true);
expect(wrapper.hasClass('modal-header')).toBe(true);
expect(wrapper.find('button.close').length).toBe(1);
expect(wrapper.find('button.btn-close').length).toBe(1);
});

it('should render custom tag', () => {
Expand All @@ -37,26 +37,4 @@ describe('ModalHeader', () => {

expect(wrapper.type()).toBe('main');
});

it('should render close button with custom aria-label', () => {
const wrapper = shallow(<ModalHeader toggle={() => {}} className="other" closeAriaLabel="oseclay">Yo!</ModalHeader>);

const closeButton = wrapper.find('button.close').first();
expect(closeButton.prop('aria-label')).toBe('oseclay');
});

it('should render close button with default icon', () => {
const wrapper = shallow(<ModalHeader toggle={() => {}}>Yo!</ModalHeader>);

const closeButtonIcon = wrapper.find('button.close span');
const defaultIcon = String.fromCharCode(215);
expect(closeButtonIcon.text()).toEqual(defaultIcon);
});

it('should render close button with custom icon', () => {
const wrapper = shallow(<ModalHeader toggle={() => {}} charCode={'X'}>Yo!</ModalHeader>);

const closeButtonIcon = wrapper.find('button.close span');
expect(closeButtonIcon.text()).toEqual('X');
});
});
38 changes: 1 addition & 37 deletions src/__tests__/ToastHeader.spec.js
Expand Up @@ -22,7 +22,7 @@ describe('ToastHeader', () => {

expect(wrapper.hasClass('other')).toBe(true);
expect(wrapper.hasClass('toast-header')).toBe(true);
expect(wrapper.find('button.close').length).toBe(1);
expect(wrapper.find('button.btn-close').length).toBe(1);
});

it('should render custom tag', () => {
Expand All @@ -37,40 +37,4 @@ describe('ToastHeader', () => {

expect(wrapper.type()).toBe('main');
});

it('should render close button with custom aria-label', () => {
const wrapper = shallow(<ToastHeader toggle={() => { }} className="other" closeAriaLabel="oseclay">Yo!</ToastHeader>);

const closeButton = wrapper.find('button.close').first();
expect(closeButton.prop('aria-label')).toBe('oseclay');
});

it('should render close button with default icon', () => {
const wrapper = shallow(<ToastHeader toggle={() => { }}>Yo!</ToastHeader>);

const closeButtonIcon = wrapper.find('button.close span');
const defaultIcon = String.fromCharCode(215);
expect(closeButtonIcon.text()).toEqual(defaultIcon);
});

it('should render close button with custom icon', () => {
const wrapper = shallow(<ToastHeader toggle={() => { }} charCode={'X'}>Yo!</ToastHeader>);

const closeButtonIcon = wrapper.find('button.close span');
expect(closeButtonIcon.text()).toEqual('X');
});

it('should render icon with a color', () => {
const wrapper = shallow(<ToastHeader icon="primary">Yo!</ToastHeader>);

const closeButtonIcon = wrapper.find('svg');
expect(closeButtonIcon.hasClass('text-primary')).toBe(true);
});

it('should render a custom icon', () => {
const wrapper = shallow(<ToastHeader icon={<span className="my-header">icon</span>}>Yo!</ToastHeader>);

const closeButtonIcon = wrapper.find('span.my-header');
expect(closeButtonIcon.text()).toEqual("icon");
});
});
1 change: 0 additions & 1 deletion types/lib/ToastHeader.d.ts
Expand Up @@ -9,7 +9,6 @@ export interface ToastHeaderProps extends React.HTMLAttributes<HTMLElement> {
toggle?: React.MouseEventHandler<any>;
icon?: string | React.ReactNode;
close?: React.ReactNode;
charCode?: string | number;
closeAriaLabel?: string;
}

Expand Down