-
-
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 Zoom in/zoom out impacts docs view #8389
Comments
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! |
WORKAROUND: I have a workaround that I implemented to prevent this, it's a script inside of <script>
const STORYBOOK_IFRAME_SELECTOR = '#storybook-preview-iframe';
const DOCS_ROOT_SELECTOR = '#docs-root';
function withIframe(iframe) {
const iframeWindow = iframe.contentWindow;
const zoomObserver = new MutationObserver(() => {
const iframeBody = iframeWindow.document.body;
const zoom = Number(iframeBody.style.zoom || 1);
const adjustedZoom = 1 / zoom;
const docsRoot = iframeBody.querySelector(DOCS_ROOT_SELECTOR);
if (docsRoot) docsRoot.style.zoom = adjustedZoom;
});
iframeWindow.addEventListener('DOMContentLoaded', () => {
zoomObserver.observe(iframeWindow.document.body, {
attributes: true,
childList: true,
subtree: true,
attributeFilter: ['style'],
});
});
}
const nodeAddedObserver = new MutationObserver(mutations => {
const iframe = document.querySelector(STORYBOOK_IFRAME_SELECTOR);
if (!iframe || !withIframe) return;
nodeAddedObserver.disconnect();
withIframe(iframe);
withIframe = null;
});
window.addEventListener('DOMContentLoaded', () => {
nodeAddedObserver.observe(document.body, {
childList: true,
subtree: true,
attributes: false,
characterData: false,
});
});
</script> Basically it just divides 1 by the current zoom of the body (the |
This is what I've been using: UPDATE: I've since updated the solution to reduce an occasional flicker, for a more optimized version use this: function fixZoomEffectForDocs(StoryFn) {
// Get page params from top level frame (host window)
const path = (window.top.location.href.split('?')[1] || '')
.replace('path=', '')
useLayoutEffect(() => {
if (path.startsWith('/docs') && document.body.style.zoom !== 1) {
// Reset zoom to allow normal view
document.body.style.zoom = 1;
}
}, [path]);
return <StoryFn />;
}
|
^ That's definitely a lot simpler than mine, I'll give that a try |
Hi! I am going through and cleaning up old issues in the repo. We just shipped a ton of improvements in Storybook 7.0, and I suspect this bug might be fixed already. Can you please try it out? If this issue persists with the latest version, please open a new bug report with a 7.x reproduction. Thank you so much! 🙏🏼 |
Describe the bug
Zooming in and out impacts the look and feel of the docs view
Expected behavior
Zooming in and out in the canvas should only impact the canvas
Additional context
version: 5.3.0-alpha.17
Example found in: Official Storybook - https://monorepo-git-next.storybook.now.sh
The text was updated successfully, but these errors were encountered: