Skip to content

Commit f223af7

Browse files
author
Malte W
committed
Add support for custom tagName. closes #63
1 parent 57da328 commit f223af7

File tree

2 files changed

+43
-27
lines changed

2 files changed

+43
-27
lines changed

src/Scrollbars/index.js

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import raf, { cancel as caf } from 'raf';
22
import css from 'dom-css';
3-
import React, { createClass, PropTypes, cloneElement } from 'react';
3+
import { createClass, createElement, PropTypes, cloneElement } from 'react';
44
import isString from '../utils/isString';
55
import getScrollbarWidth from '../utils/getScrollbarWidth';
66
import returnFalse from '../utils/returnFalse';
@@ -13,7 +13,6 @@ import {
1313
viewStyleDefault,
1414
viewStyleAutoHeight,
1515
viewStyleUniversalInitial,
16-
viewStyleAutoHeightUniversalInitial,
1716
trackHorizontalStyleDefault,
1817
trackVerticalStyleDefault,
1918
thumbHorizontalStyleDefault,
@@ -45,6 +44,7 @@ export default createClass({
4544
renderTrackVertical: PropTypes.func,
4645
renderThumbHorizontal: PropTypes.func,
4746
renderThumbVertical: PropTypes.func,
47+
tagName: PropTypes.string,
4848
thumbSize: PropTypes.number,
4949
thumbMinSize: PropTypes.number,
5050
hideTracksWhenNotNeeded: PropTypes.bool,
@@ -72,6 +72,7 @@ export default createClass({
7272
renderTrackVertical: renderTrackVerticalDefault,
7373
renderThumbHorizontal: renderThumbHorizontalDefault,
7474
renderThumbVertical: renderThumbVerticalDefault,
75+
tagName: 'div',
7576
thumbMinSize: 30,
7677
hideTracksWhenNotNeeded: false,
7778
autoHide: false,
@@ -522,6 +523,7 @@ export default createClass({
522523
renderTrackVertical,
523524
renderThumbHorizontal,
524525
renderThumbVertical,
526+
tagName,
525527
hideTracksWhenNotNeeded,
526528
autoHide,
527529
autoHideTimeout,
@@ -595,30 +597,28 @@ export default createClass({
595597
})
596598
};
597599

598-
return (
599-
<div {...props} style={containerStyle} ref="container">
600-
{cloneElement(
601-
renderView({ style: viewStyle }),
602-
{ ref: 'view' },
603-
children
604-
)}
605-
{cloneElement(
606-
renderTrackHorizontal({ style: trackHorizontalStyle }),
607-
{ ref: 'trackHorizontal' },
608-
cloneElement(
609-
renderThumbHorizontal({ style: thumbHorizontalStyleDefault }),
610-
{ ref: 'thumbHorizontal' }
611-
)
612-
)}
613-
{cloneElement(
614-
renderTrackVertical({ style: trackVerticalStyle }),
615-
{ ref: 'trackVertical' },
616-
cloneElement(
617-
renderThumbVertical({ style: thumbVerticalStyleDefault }),
618-
{ ref: 'thumbVertical' }
619-
)
620-
)}
621-
</div>
622-
);
600+
return createElement(tagName, { ...props, style: containerStyle, ref: 'container' }, [
601+
cloneElement(
602+
renderView({ style: viewStyle }),
603+
{ key: 'view', ref: 'view' },
604+
children
605+
),
606+
cloneElement(
607+
renderTrackHorizontal({ style: trackHorizontalStyle }),
608+
{ key: 'trackHorizontal', ref: 'trackHorizontal' },
609+
cloneElement(
610+
renderThumbHorizontal({ style: thumbHorizontalStyleDefault }),
611+
{ ref: 'thumbHorizontal' }
612+
)
613+
),
614+
cloneElement(
615+
renderTrackVertical({ style: trackVerticalStyle }),
616+
{ key: 'trackVertical', ref: 'trackVertical' },
617+
cloneElement(
618+
renderThumbVertical({ style: thumbVerticalStyleDefault }),
619+
{ ref: 'thumbVertical' }
620+
)
621+
)
622+
]);
623623
}
624624
});

test/Scrollbars/rendering.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,22 @@ export default function createTests(scrollbarWidth) {
5050
});
5151
});
5252

53+
describe('when using custom tagName', () => {
54+
it('should use the defined tagName', done => {
55+
render((
56+
<Scrollbars
57+
tagName="nav"
58+
style={{ width: 100, height: 100 }}>
59+
<div style={{ width: 200, height: 200 }}/>
60+
</Scrollbars>
61+
), node, function callback() {
62+
const el = findDOMNode(this);
63+
expect(el.tagName.toLowerCase()).toEqual('nav');
64+
done();
65+
});
66+
});
67+
});
68+
5369
describe('when custom `renderView` is passed', () => {
5470
it('should render custom element', done => {
5571
render((

0 commit comments

Comments
 (0)