-
Notifications
You must be signed in to change notification settings - Fork 723
feat: add direction option for RTL menu support #797
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
Open
bbrala
wants to merge
4
commits into
master
Choose a base branch
from
feat/issue-742-rtl-direction-option
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
3655bdf
feat: add direction option for RTL menu support
bbrala 58794b2
fix: clamp flipped RTL detached submenu against the right viewport edge
bbrala e34ffb9
Merge origin/master into feat/issue-742-rtl-direction-option
bbrala 776df42
test: add regression coverage for rtl direction + overflowing sub-menu
bbrala File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| --- | ||
| currentMenu: rtl-long-submenu | ||
| --- | ||
|
|
||
| # Demo: RTL menu with a long (overflowing) sub-menu | ||
|
|
||
| <!-- START doctoc generated TOC please keep comment here to allow auto update --> | ||
| <!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE --> | ||
|
|
||
|
|
||
| - [Example code](#example-code) | ||
| - [Example HTML](#example-html) | ||
|
|
||
| <!-- END doctoc generated TOC please keep comment here to allow auto update --> | ||
|
|
||
| <span class="context-menu-one btn btn-neutral">right click me</span> | ||
|
|
||
| ## Example code | ||
|
|
||
| <script type="text/javascript" class="showcase"> | ||
| $(function(){ | ||
| /************************************************** | ||
| * Combined regression coverage for `direction: 'rtl'` | ||
| * (#742) together with a sub-menu taller than the | ||
| * viewport (#752): the sub-menu must still open on | ||
| * the LEFT of its parent item (RTL) AND be detached, | ||
| * capped to the viewport and scrollable, exactly like | ||
| * the plain LTR case in long-submenu-short-root.md. | ||
| **************************************************/ | ||
| var subItems = {}; | ||
| for (var i = 1; i <= 40; i++) { | ||
| subItems['sub-key' + i] = {name: 'Sub item ' + i}; | ||
| } | ||
|
|
||
| $.contextMenu({ | ||
| selector: '.context-menu-one', | ||
| direction: 'rtl', | ||
| callback: function(key, options) { | ||
| var m = "clicked: " + key; | ||
| window.console && console.log(m) || alert(m); | ||
| }, | ||
| items: { | ||
| item1: {name: 'Item 1'}, | ||
| item2: {name: 'Item 2'}, | ||
| fold1: { | ||
| name: 'Long sub group', | ||
| items: subItems | ||
| } | ||
| } | ||
| }); | ||
| }); | ||
| </script> | ||
|
|
||
| ## Example HTML | ||
| <div style="display:none;" class="showcase" data-showcase-import=".context-menu-one"></div> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| const { test, expect } = require('@playwright/test'); | ||
| const { fixture, expectAlert } = require('../support/helpers'); | ||
|
|
||
| // Regression test for the combination of `direction: 'rtl'` (#742) and a | ||
| // sub-menu taller than the viewport (#752): these two features both modify | ||
| // positionSubmenu() in src/jquery.contextMenu.js (see the merge commit that | ||
| // combined them), so this exercises them together rather than trusting that | ||
| // each one working in isolation (covered separately by | ||
| // test/unit/direction-rtl.test.js and test/specs/overflow-submenu-only.js) | ||
| // means the combined logic is also correct. | ||
| test.describe('Test direction: "rtl" together with an overflowing sub-menu (#742 + #752)', () => { | ||
| test.use({ viewport: { width: 1000, height: 500 } }); | ||
|
|
||
| test('an overflowing sub-menu still opens to the left in rtl mode, and is capped/scrollable', async ({ page }) => { | ||
| await page.goto(fixture('rtl-long-submenu.html')); | ||
| await page.click('.context-menu-one', { button: 'right' }); | ||
|
|
||
| const menu = page.locator('.context-menu-root'); | ||
| await expect(menu).toBeVisible(); | ||
| await expect(menu).toHaveClass(/context-menu-rtl/); | ||
|
|
||
| const opener = page.locator('span:text-is("Long sub group")'); | ||
| const openerBox = await opener.boundingBox(); | ||
|
|
||
| await opener.hover(); | ||
|
|
||
| const submenu = page.locator('.context-menu-list:not(.context-menu-root)'); | ||
| await expect(submenu).toBeVisible(); | ||
| await expect(submenu).toHaveClass(/context-menu-rtl/); | ||
|
|
||
| const submenuBox = await submenu.boundingBox(); | ||
|
|
||
| // rtl: the sub-menu should open to the LEFT of its opener, not the right | ||
| expect(submenuBox.x).toBeLessThanOrEqual(openerBox.x); | ||
|
|
||
| // ...and, despite opening on a different side, it must still be capped | ||
| // to the viewport height and made scrollable rather than clipped | ||
| // (the same #752 behaviour as the plain ltr case) | ||
| const viewportHeight = page.viewportSize().height; | ||
| expect(submenuBox.y + submenuBox.height).toBeLessThanOrEqual(viewportHeight); | ||
|
|
||
| // the last item must actually be reachable via the sub-menu's own | ||
| // internal scroll container | ||
| await submenu.evaluate((el) => { | ||
| el.scrollTop = el.scrollHeight; | ||
| }); | ||
|
|
||
| const lastItem = page.locator('span:text-is("Sub item 40")'); | ||
| await expect(lastItem).toBeInViewport(); | ||
| await expectAlert( | ||
| page, | ||
| () => lastItem.click(), | ||
| 'clicked: sub-key40' | ||
| ); | ||
| }); | ||
| }); |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When a detached RTL submenu cannot fit to the left of an opener near the viewport's left edge, this branch flips it to the right but never checks whether
left + menuWidthnow exceeds the viewport's right edge. If neither side has enough room, the submenu therefore remains partially off-screen instead of receiving the edge-clamping behavior described here; clamp the flipped result against the right boundary before applying the existing left clamp.Useful? React with 👍 / 👎.