Skip to content

Commit 446b49a

Browse files
committed
remove id prop in favor of selector
This removes a "redundant" feature and simplify the API surface. Also using id as prop may be confusing with the DOM id attribute.
1 parent 2076f61 commit 446b49a

File tree

3 files changed

+9
-13
lines changed

3 files changed

+9
-13
lines changed

src/ElementPortal.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,8 @@ const ElementPortal = createReactClass({
2323
},
2424

2525
renderToNodes() {
26-
const nodeById = this.props.id && document.getElementById(this.props.id);
27-
const nodesById = nodeById ? [nodeById] : [];
2826
const mapDomNodeToProps = this.props.mapDomNodeToProps || noop;
29-
const nodesBySelector = (this.props.selector && [].slice.call(document.querySelectorAll(this.props.selector))) || [];
30-
const nodes = nodesById.concat(nodesBySelector);
27+
const nodes = (this.props.selector && [].slice.call(document.querySelectorAll(this.props.selector))) || [];
3128
const { component } = this.props;
3229

3330
nodes.forEach(node => {

src/withElementPortal.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,9 @@ function getDisplayName(Component) {
66
}
77

88
const withElementPortal = (Child) => {
9-
const Portal = ({ id, selector, shouldReset, mapDomNodeToProps, ...childProps }) => {
9+
const Portal = ({ selector, shouldReset, mapDomNodeToProps, ...childProps }) => {
1010
const ChildWrapper = (props) => <Child {...childProps} {...props} />;
1111
return <ElementPortal
12-
id={id}
1312
selector={selector}
1413
mapDomNodeToProps={mapDomNodeToProps}
1514
shouldReset={shouldReset}

test/ElementPortal.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ test('can render to ElementPortal using element id', t => {
2323
const Greeting = () => (<div>Hello</div>);
2424
render(
2525
<div>
26-
<ElementPortal id={headerId}>
26+
<ElementPortal selector={`#${headerId}`}>
2727
<Greeting/>
2828
</ElementPortal>
2929
</div>,
@@ -127,7 +127,7 @@ test('erases classes and styles', t => {
127127
const Greeting = () => (<div>Hello</div>);
128128
render(
129129
<div>
130-
<ElementPortal id={headerId} shouldReset>
130+
<ElementPortal selector={`#${headerId}`} shouldReset>
131131
<Greeting/>
132132
</ElementPortal>
133133
</div>,
@@ -162,7 +162,7 @@ test('transfers context to the portal', t => {
162162
render(
163163
<Provider store={store}>
164164
<div>
165-
<ElementPortal id={headerId}>
165+
<ElementPortal selector={`#${headerId}`}>
166166
<CountContainer/>
167167
</ElementPortal>
168168
</div>
@@ -190,7 +190,7 @@ test('can be used as higher-order component', t => {
190190

191191
render(
192192
<div>
193-
<GreetingWithPortal id={headerId} />
193+
<GreetingWithPortal selector={`#${headerId}`} />
194194
</div>,
195195
document.getElementById(appId)
196196
);
@@ -221,7 +221,7 @@ test('can be composed with other HOC\'s', t => {
221221

222222
render(
223223
<Provider store={store}>
224-
<MyComposedComponent id={headerId} />
224+
<MyComposedComponent selector={`#${headerId}`} />
225225
</Provider>,
226226
document.getElementById(appId)
227227
);
@@ -247,7 +247,7 @@ test('map dom node to props when used as HOC', t => {
247247

248248
render(
249249
<div>
250-
<GreetingWithPortal id={headerId} mapDomNodeToProps={mapDomNodeToProps} />
250+
<GreetingWithPortal selector={`#${headerId}`} mapDomNodeToProps={mapDomNodeToProps} />
251251
</div>,
252252
document.getElementById(appId)
253253
);
@@ -270,7 +270,7 @@ test('passes props through to the inner component when used as a HOC', t => {
270270

271271
render(
272272
<div>
273-
<GreetingWithPortal id={headerId} name="Joe" />
273+
<GreetingWithPortal selector={`#${headerId}`} name="Joe" />
274274
</div>,
275275
document.getElementById(appId)
276276
);

0 commit comments

Comments
 (0)