Skip to content
This repository was archived by the owner on Mar 27, 2021. It is now read-only.

Commit b8ae045

Browse files
authored
Merge pull request #57 from stripe/jenan-classname
Allow `*Element` components to take `className`.
2 parents 5e14d8d + 19f51ee commit b8ae045

File tree

3 files changed

+14
-2
lines changed

3 files changed

+14
-2
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,7 @@ These components accept all `options` that can be passed into `elements.create(t
219219

220220
```js
221221
type ElementProps = {
222+
className?: string,
222223
elementRef?: (StripeElement) => void,
223224

224225
// For full documentation on the events and payloads below, see:

src/components/Element.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import shallowEqual from '../utils/shallowEqual';
55
import type {ElementContext} from './Elements';
66

77
type Props = {
8+
className: string,
89
elementRef: Function,
910
onChange: Function,
1011
onBlur: Function,
@@ -17,13 +18,15 @@ const noop = () => {};
1718
const Element = (type: string, hocOptions: {sourceType?: string} = {}) =>
1819
class extends React.Component {
1920
static propTypes = {
21+
className: PropTypes.string,
2022
elementRef: PropTypes.func,
2123
onChange: PropTypes.func,
2224
onBlur: PropTypes.func,
2325
onFocus: PropTypes.func,
2426
onReady: PropTypes.func,
2527
};
2628
static defaultProps = {
29+
className: '',
2730
elementRef: noop,
2831
onChange: noop,
2932
onBlur: noop,
@@ -88,6 +91,7 @@ const Element = (type: string, hocOptions: {sourceType?: string} = {}) =>
8891

8992
_extractOptions(props: Props): Object {
9093
const {
94+
className,
9195
elementRef,
9296
onChange,
9397
onFocus,
@@ -102,7 +106,7 @@ const Element = (type: string, hocOptions: {sourceType?: string} = {}) =>
102106
this._ref = ref;
103107
};
104108
render() {
105-
return <span ref={this.handleRef} />;
109+
return <span className={this.props.className} ref={this.handleRef} />;
106110
}
107111
};
108112

src/components/Element.test.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// @noflow
22
import React from 'react';
3-
import {mount} from 'enzyme';
3+
import {mount, shallow} from 'enzyme';
44

55
import Element from './Element';
66

@@ -25,6 +25,13 @@ describe('Element', () => {
2525
};
2626
});
2727

28+
it('should pass className to the DOM element', () => {
29+
const className = 'my-class';
30+
const CardElement = Element('card', {sourceType: 'card'});
31+
const element = shallow(<CardElement className={className} />, {context});
32+
expect(element.first().hasClass(className)).toBeTruthy();
33+
});
34+
2835
it('should call the right hooks for a source Element', () => {
2936
const SourceElement = Element('source', {sourceType: 'foobar'});
3037
const element = mount(<SourceElement onChange={jest.fn()} />, {context});

0 commit comments

Comments
 (0)