Skip to content

Commit afc5b49

Browse files
NemeZZiZZdanielbarion
authored andcommitted
added attribute to disable internal styling
1 parent b081a2a commit afc5b49

File tree

1 file changed

+26
-16
lines changed

1 file changed

+26
-16
lines changed

src/index.js

Lines changed: 26 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,8 @@ class ReactTooltip extends React.Component {
7474
bodyMode: PropTypes.bool,
7575
possibleCustomEvents: PropTypes.string,
7676
possibleCustomEventsOff: PropTypes.string,
77-
clickable: PropTypes.bool
77+
clickable: PropTypes.bool,
78+
disableInternalStyle: PropTypes.bool
7879
};
7980
}
8081

@@ -152,12 +153,15 @@ class ReactTooltip extends React.Component {
152153
}
153154

154155
componentDidMount() {
155-
const { insecure, resizeHide } = this.props;
156+
const { insecure, resizeHide, disableInternalStyle } = this.props;
156157
this.mount = true;
157158

158159
this.bindListener(); // Bind listener for tooltip
159160
this.bindWindowEvents(resizeHide); // Bind global event for static method
160-
this.injectStyles(); // Inject styles for each DOM root having tooltip.
161+
162+
if (!disableInternalStyle) {
163+
this.injectStyles(); // Inject styles for each DOM root having tooltip.
164+
}
161165
}
162166

163167
static getDerivedStateFromProps(nextProps, prevState) {
@@ -798,14 +802,16 @@ class ReactTooltip extends React.Component {
798802
const { extraClass, html, ariaProps, disable, uuid } = this.state;
799803
const content = this.getTooltipContent();
800804
const isEmptyTip = this.isEmptyTip(content);
801-
const style = generateTooltipStyle(
802-
this.state.uuid,
803-
this.state.customColors,
804-
this.state.type,
805-
this.state.border,
806-
this.state.padding,
807-
this.state.customRadius
808-
);
805+
const style = this.props.disableInternalStyle
806+
? ''
807+
: generateTooltipStyle(
808+
this.state.uuid,
809+
this.state.customColors,
810+
this.state.type,
811+
this.state.border,
812+
this.state.padding,
813+
this.state.customRadius
814+
);
809815

810816
const tooltipClass =
811817
'__react_component_tooltip' +
@@ -828,7 +834,9 @@ class ReactTooltip extends React.Component {
828834
.join(' ');
829835

830836
if (html) {
831-
const htmlContent = `${content}\n<style aria-hidden="true">${style}</style>`;
837+
const htmlContent = `${content}${
838+
style ? `\n<style aria-hidden="true">${style}</style>` : ''
839+
}`;
832840

833841
return (
834842
<Wrapper
@@ -849,10 +857,12 @@ class ReactTooltip extends React.Component {
849857
ref={(ref) => (this.tooltipRef = ref)}
850858
data-id="tooltip"
851859
>
852-
<style
853-
dangerouslySetInnerHTML={{ __html: style }}
854-
aria-hidden="true"
855-
/>
860+
{style && (
861+
<style
862+
dangerouslySetInnerHTML={{ __html: style }}
863+
aria-hidden="true"
864+
/>
865+
)}
856866
{content}
857867
</Wrapper>
858868
);

0 commit comments

Comments
 (0)