Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[EuiPageSidebar] Fix inline styles not updating if sticky is not set #6191

Merged
merged 3 commits into from
Aug 29, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 44 additions & 1 deletion src/components/page/page_sidebar/page_sidebar.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
*/

import React from 'react';
import { render } from 'enzyme';
import { render, mount } from 'enzyme';
import { requiredProps } from '../../../test/required_props';
import { shouldRenderCustomStyles } from '../../../test/internal';
import { PADDING_SIZES } from '../../../global_styling';
Expand Down Expand Up @@ -44,4 +44,47 @@ describe('EuiPageSidebar', () => {
});
});
});

describe('inline styles', () => {
it('updates correctly when `sticky` is not set', () => {
const component = mount(<EuiPageSidebar data-test-subj="sidebar" />);

expect(
component.find('[data-test-subj="sidebar"]').last().prop('style')
).toEqual({ minInlineSize: 248 });

component.setProps({ minWidth: 100 });
component.update();

expect(
component.find('[data-test-subj="sidebar"]').last().prop('style')
).toEqual({ minInlineSize: 100 });
});

it('updates correctly when `sticky` is set', () => {
const component = mount(
<EuiPageSidebar sticky data-test-subj="sidebar" />
);

expect(
component.find('[data-test-subj="sidebar"]').last().prop('style')
).toEqual({
insetBlockStart: 0,
maxBlockSize: 'calc(100vh - 0px)',
minInlineSize: 248,
});

component.setProps({ style: { color: 'red' } });
component.update();

expect(
component.find('[data-test-subj="sidebar"]').last().prop('style')
).toEqual({
color: 'red',
insetBlockStart: 0,
maxBlockSize: 'calc(100vh - 0px)',
minInlineSize: 248,
});
});
});
});
14 changes: 10 additions & 4 deletions src/components/page/page_sidebar/page_sidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,11 @@ export const EuiPageSidebar: FunctionComponent<EuiPageSidebarProps> = ({
});

useEffect(() => {
let updatedStyles = {
...style,
...logicalStyle('min-width', isResponding ? '100%' : minWidth),
};

if (sticky) {
const euiHeaderFixedCounter = Number(
document.body.dataset.fixedHeaders ?? 0
Expand All @@ -91,13 +96,14 @@ export const EuiPageSidebar: FunctionComponent<EuiPageSidebarProps> = ({
? sticky?.offset
: themeContext.euiTheme.base * 3 * euiHeaderFixedCounter;

setInlineStyles({
...style,
...logicalStyle('min-width', isResponding ? '100%' : minWidth),
updatedStyles = {
...updatedStyles,
...logicalStyle('top', offset),
...logicalStyle('max-height', `calc(100vh - ${offset}px)`),
});
};
}

setInlineStyles(updatedStyles);
}, [style, sticky, themeContext.euiTheme.base, isResponding, minWidth]);

return (
Expand Down
3 changes: 3 additions & 0 deletions upcoming_changelogs/6191.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
**Bug fixes**

- Fixed an `EuiPageSidebar` bug where inline styles were not correctly updating