Skip to content

Commit

Permalink
fix focus on init
Browse files Browse the repository at this point in the history
  • Loading branch information
kseniya57 committed Dec 9, 2020
1 parent f9869c8 commit 39688fd
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 16 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@idui/react-popover",
"version": "1.0.0",
"version": "1.0.1",
"description": "React Popover Component",
"author": "kaprisa57@gmail.com",
"license": "MIT",
Expand Down
22 changes: 9 additions & 13 deletions src/__tests__/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -315,9 +315,7 @@ describe('Popover', () => {
await waitFor(() => expect(getByTestId('content')).toBeInTheDocument());

fireEvent.mouseDown(button, { which: 0 });
await waitFor(() =>
expect(getByTestId('content')).toBeInTheDocument()
);
await waitFor(() => expect(getByTestId('content')).toBeInTheDocument());
});

it('closes on escape key press', async () => {
Expand All @@ -339,20 +337,18 @@ describe('Popover', () => {

it('does not close on any button press (except for buttons in props)', async () => {
const { getByTestId } = render(
<Popover
placement="leftBottom"
content={<span data-testid="content">Hi!</span>}
closeOnEnter
>
<button data-testid="button">Open</button>
</Popover>
<Popover
placement="leftBottom"
content={<span data-testid="content">Hi!</span>}
closeOnEnter
>
<button data-testid="button">Open</button>
</Popover>
);
user.click(getByTestId('button'));
await waitFor(() => expect(getByTestId('content')).toBeInTheDocument());
fireEvent.keyDown(document.body, { key: 'Shift', code: 'Shift' });
await waitFor(() =>
expect(getByTestId('content')).toBeInTheDocument()
);
await waitFor(() => expect(getByTestId('content')).toBeInTheDocument());
});

it('closes on enter key press', async () => {
Expand Down
5 changes: 4 additions & 1 deletion src/components/Popover/LazyPopover.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@ function LazyPopover(props, ref) {
} = props;

const [isInitialized, setInitialized] = useState(
() => providedIsOpen || _.isFunction(children)
() =>
providedIsOpen ||
_.isFunction(children) ||
trigger === POPOVER_TRIGGER_TYPES.focus
);
const [isOpen, setOpen] = useState(providedIsOpen);

Expand Down
2 changes: 1 addition & 1 deletion src/components/Popover/popover.stories.js
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ export default {
defaultValue: {
initial: { opacity: 0, scale: 0.9 },
animate: { opacity: 1, scale: 1 },
exit: { opacity: 0, scale: 0.9, transition: { duration: 0.1 } }
exit: { opacity: 0, scale: 0.9, transition: { duration: 0.1 } },
},
table: {
defaultValue: {
Expand Down

0 comments on commit 39688fd

Please sign in to comment.