-
-
Notifications
You must be signed in to change notification settings - Fork 9.4k
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
[addon-docs] Component with position:fixed leaks out from Preview #8011
Comments
@chrsep not sure, but can you wrap your component in a container with styling as needed instead of storybooks adding styles that can interfere with other types of components? |
@atanasster Yes, i can do that. I can see why adding styles directly to storybook can be problematic. But I feel that this might be something that would be better solved directly on storybook, other people might get confused when their components jumps out of the preview block. It kinda surprises me when that happen, i didn't expect my component to be able to affect or be affected by stuffs outside the preview block. I guess i sort of expected it to work like a miniaturized canvas page that have iframe that fully contained my code. |
@chrsep i'm open to styling the container differently. i'll play around with your solution! |
Hi everyone! Seems like there hasn't been much going on in this issue lately. If there are still questions, comments, or bugs, please feel free to continue the discussion. Unfortunately, we don't have time to get to every issue. We are always open to contributions so please send us a pull request if you would like to help. Inactive issues will be closed after 30 days. Thanks! |
Id want to add to this. We have a component that is a navigation which has a fixed position and top: 0; left: 0. We want this component to be fixed to the top of the screen at all times. This looks great when we have the component in the canvas, but when trying to leverage docs it looks very weird. Ideally this would somehow be contained in the preview window. This causes issues because of navigation component has 3 different examples of the options as stories and they all overlay ontop of each other. |
I found decorators useful here as a temp fix: import React from 'react';
import { action } from '@storybook/addon-actions';
import bagItems from '../../../lib/bagItems';
import MiniBag from './Header__minibag';
const styles = {
transform: 'scale(1)',
height: '100vh',
};
export default {
title: 'Components|Header/Minibag',
component: MiniBag,
decorators: [storyFn => <div style={styles}>{storyFn()}</div>],
};
export const basic = () => (
<MiniBag
minibagItems={bagItems[0]}
active
toggleMinibag={action('toggleMinibag')}
/>
);
basic.story = {
name: 'Default',
}; They can be used to add some Story Book only styles so you don't see styling issues when using |
@morganfeeney Thank you for your suggestion. Sadly this also breaks the CSS logic of fixed elements since they will now be fixed to that container and not the viewport. I think the only valid solution would be to render each preview in an iframe otherwise there is no way to support fixed elements (this is just how CSS works) |
@pixelass you can force Storybook to render your Docs story in an iframe, globally, per component, or per story https://storybook.js.org/docs/react/writing-docs/doc-blocks#inline-rendering |
@pixelass you are welcome, but it is only a suggestion, a mere workaround to help people out if they get here and are in a hurry to get things working quickly. You got me thinking about CSS, what I found is that adding a transform is a valid way to change the containing block from the viewport: https://developer.mozilla.org/en-US/docs/Web/CSS/position#fixed |
@morganfeeney Thank you. I did not know that one can force iframe rendering. I did hit another issue though and I have the feeling this is not documented anywhere: https://storybook.js.org/docs/react/writing-docs/docs-page#inline-stories-vs-iframe-stories
It neither states how to set the height nor does it link to a section of the docs where it is documented. Searching for "height" within the docs also returned no results. I would be willing to fix the missing parts in the documentation once I find a solution. I tried this without success: function withWrapper(style: React.CSSProperties) {
return f => <div style={style}>{f()}</div>;
}
const story = {
component: MyComponent,
title: "Foo/Bar/My Component",
decorators: [ withWrapper({
height: 500,
})]
}; I ended up disabling "docs" for the components with this issue for now. Since we have a separation of docs and examples this doesn't bother us too much right now.
Also to answer your statement:
That is in fact true but changing the containing block causes other features to not work as expected. Fixing the element to the top would be the biggest impact. Obviously there are ways to rewrite the components to fix this issue but I strongly suggest against adjusting styles "only to support" that the Components can be rendered inline. Features that will not work or experience issues could be:
|
@pixelass you can force the iframe height using the |
👋 Could please tell me if it works for y'all? Demo is here |
w00t!! I just released https://github.com/storybookjs/storybook/releases/tag/v6.1.0-alpha.8 containing PR #11350 that references this issue. Upgrade today to try it out! You can find this prerelease on the Closing this issue. Please re-open if you think there's still more to do. |
@shilman I updated I also tried this code: (but the height is not applied). const story: Meta = {
component: Grid,
title: "Design System/Layout/Grid",
parameters: {
docs: {
inlineStories: false,
story: {
iFrameHeight: 500,
},
},
},
}; |
@pixelass |
@frassinier can you help @pixelass with the original issue? |
My bad. I tried |
Actually, it's not designed to be used with CSF but with MDX: <Story name="custom-height" height="500px">
<YourComponentUsingFixingPosition />
</story> @shilman I can try to add it to this interface, in addition? |
@frassinier you just found the issue... 💯 The issue was {docs: {story: { iframeHeight: 500}}} should be {docs: { iframeHeight: 500}} (not nested under the |
Looks like we're good @frassinier. Thanks! |
Thank you dude! This worked nicely for me! |
I tried setting the iframeHeight and inlineStories property but it didnt work for me. I also tried with decorators as suggested but still no success. this is the code of my mdx file: <Meta |
This solved it for me
|
You might try wrapping a div around your story with the following CSS:
|
- Storybook에서 position: fixed가 제대로 되지 않는 현상이 발생하고 있다. - 따라서 absolute로 임시방편 후 주석을 달아놓았다. - 참고: storybookjs/storybook#8011
If your file extension is const meta = {
title: "UI/SideBar",
component: () => (
<div style={{ minHeight: "200px" }}>
<SideBar />
</div>
),
... |
… vises feil i docs-fanen i storybook Bugen er kjent for Storybook, men de har ikke implementert noen fiks enda: storybookjs/storybook#23586 Det er flere som har laget workarounds, en er å rendre story som en iframe istedenfor inline ved å sette inline false https://storybook.js.org/docs/api/doc-block-story#inline , som foreslått i denne tråden storybookjs/storybook#8011 . Det er noen ulemper med dette, lettest å vise i code review Related work items: #322120
Describe the bug
When a component with css
position:fixed
is displayed on the Docs page, it's fixed to the viewport, leaks out of the preview box, and does not scroll with the page. I've noticed that addingtransform: scale(1)
to the parent of theposition:fixed
component (tried it by pressing the the zoom button) clips and bound theposition:fixed
element correctly.To Reproduce
Steps to reproduce the behavior:
position: fixed
Expected behavior
All element of the component that is rendered inside the Docs preview should be contained inside the preview.
Screenshots
The Bug
Expected (this is with
transform:scale(1)
)System:
Additional context
Source Code
Live Storybook
The text was updated successfully, but these errors were encountered: