Skip to content

Commit

Permalink
fix(popover): update autoAlign to work when open is initially false (#…
Browse files Browse the repository at this point in the history
…12938)

Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
  • Loading branch information
tay1orjones and kodiakhq[bot] authored Jan 18, 2023
1 parent f4d0253 commit b568e8a
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
26 changes: 25 additions & 1 deletion packages/react/src/components/Popover/Popover.stories.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import './story.scss';
import { Checkbox } from '@carbon/icons-react';
import React from 'react';
import React, { useState } from 'react';
import { Popover, PopoverContent } from '../Popover';
import mdx from './Popover.mdx';

Expand Down Expand Up @@ -129,8 +129,32 @@ Playground.story = {
};

export const AutoAlign = () => {
const [open, setOpen] = useState(false);
return (
<div>
<div
style={{
position: 'absolute',
bottom: 0,
right: '50%',
margin: '3rem',
}}>
<Popover open={open} autoAlign>
<div className="playground-trigger">
<Checkbox
onClick={() => {
setOpen(!open);
}}
/>
</div>
<PopoverContent className="p-3">
<p className="popover-title">Available storage</p>
<p className="popover-details">
This server has 150 GB of block storage remaining.
</p>
</PopoverContent>
</Popover>
</div>
<Popover open autoAlign>
<div className="playground-trigger">
<Checkbox />
Expand Down
6 changes: 5 additions & 1 deletion packages/react/src/components/Popover/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@ const Popover = React.forwardRef(function Popover(props, forwardRef) {
});

useIsomorphicEffect(() => {
if (!open) {
return;
}

if (!autoAlign) {
setAutoAligned(false);
return;
Expand Down Expand Up @@ -166,7 +170,7 @@ const Popover = React.forwardRef(function Popover(props, forwardRef) {
setAutoAligned(true);
setAutoAlignment(alignment);
}
}, [autoAligned, align, autoAlign, prefix]);
}, [autoAligned, align, autoAlign, prefix, open]);

return (
<PopoverContext.Provider value={value}>
Expand Down

0 comments on commit b568e8a

Please sign in to comment.