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

Menu out of bounds with animation bug fix #188

Closed
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
8 changes: 8 additions & 0 deletions cypress/integration/context-menu.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,14 @@ describe('Context menu', () => {
cy.getByDataTest(DATA_TEST.CONTEXT_MENU).isWithinViewport();
});

it('Prevent from rendering outside of the viewport if possible when menu is already visible and show is triggered and has animation', () => {
cy.viewport(500, 500);
cy.getByDataTest(DATA_TEST.CONTEXT_MENU_TRIGGER).rightclick(10, 170);
cy.getByDataTest(DATA_TEST.CONTEXT_MENU_TRIGGER).rightclick(11, 171, { force: true });
cy.getByDataTest(DATA_TEST.CONTEXT_MENU).should('be.visible');
cy.getByDataTest(DATA_TEST.CONTEXT_MENU).isWithinViewport();
});

it('Can change trigger event', () => {
cy.getByDataTest(DATA_TEST.EVENT_SELECTOR).select('onClick');
cy.getByDataTest(DATA_TEST.CONTEXT_MENU_TRIGGER).rightclick();
Expand Down
2 changes: 1 addition & 1 deletion example/components/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ function getDataTestSelector(key: string) {
export function App() {
const [state, setState] = React.useReducer(selectorReducer, {
theme: selector.themes[0],
animation: false,
animation: 'scale',
event: selector.events[0],
hideItems: false,
customPosition: false,
Expand Down
12 changes: 7 additions & 5 deletions src/components/Menu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -166,15 +166,17 @@ export const Menu: React.FC<MenuProps> = ({
y -= y + menuHeight - windowHeight;
}

setState({
x,
y,
});
if (x !== state.x || y !== state.y) {
setState({
x,
y,
});
}
}

// state.visible and state{x,y} are updated together
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [state.visible]);
}, [state.visible, state.x, state.y]);

// subscribe dom events
useEffect(() => {
Expand Down