Skip to content

Commit

Permalink
fix(applyStyles): don't remove reference inline styles
Browse files Browse the repository at this point in the history
  • Loading branch information
atomiks committed Feb 9, 2020
1 parent 0789910 commit 5399733
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 12 deletions.
24 changes: 12 additions & 12 deletions src/modifiers/applyStyles.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,21 +47,21 @@ function effect({ state }: ModifierArguments<{||}>) {
return () => {
Object.keys(state.elements).forEach(name => {
const element = state.elements[name];
const attributes = state.attributes[name] || {};

const styleProperties = Object.keys(
state.styles.hasOwnProperty(name)
? { ...state.styles[name] }
? state.styles[name]
: name === 'reference'
? {}
: initialStyles
);
const attributes = state.attributes[name] || {};

// Set all values to an empty string to unset them
const style = styleProperties.reduce(
(style, property) => ({
...style,
[String(property)]: '',
}),
{}
);
const style = styleProperties.reduce((style, property) => {
style[property] = '';
return style;
}, {});

// arrow is optional + virtual elements
if (!isHTMLElement(element) || !getNodeName(element)) {
Expand All @@ -73,9 +73,9 @@ function effect({ state }: ModifierArguments<{||}>) {
// $FlowFixMe
Object.assign(element.style, style);

Object.keys(attributes).forEach(attribute =>
element.removeAttribute(attribute)
);
Object.keys(attributes).forEach(attribute => {
element.removeAttribute(attribute);
});
});
};
}
Expand Down
15 changes: 15 additions & 0 deletions src/modifiers/applyStyles.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// @flow
import { createPopper } from '../../src/popper';

it('does not remove inline style properties from the reference', () => {
const reference = document.createElement('div');
const popper = document.createElement('div');

reference.style.position = 'absolute';
reference.style.margin = '10px';

createPopper(reference, popper).destroy();

expect(reference.style.position).toBe('absolute');
expect(reference.style.margin).toBe('10px');
});

0 comments on commit 5399733

Please sign in to comment.