-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(menu): apply default values for menuItems (#344)
BREAKING CHANGE: URL fragment no longer affects menu items selection. Now we only find matches between path part of the URL and `link` property of menu-item.
- Loading branch information
1 parent
0aa898b
commit 674eef5
Showing
7 changed files
with
170 additions
and
26 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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 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,39 @@ | ||
/** | ||
* @license | ||
* Copyright Akveo. All Rights Reserved. | ||
* Licensed under the MIT License. See License.txt in the project root for license information. | ||
*/ | ||
|
||
import { isUrlPathContain, isUrlPathEqual } from './url-matching-helpers'; | ||
|
||
|
||
describe('menu URL helpers', () => { | ||
it('isUrlPathContain should work by url segments', () => { | ||
expect(isUrlPathContain('/a/ba', '/a/b')).toBeFalsy(); | ||
expect(isUrlPathContain('/a/b/c', '/a/b')).toBeTruthy(); | ||
}); | ||
|
||
it('isUrlPathContain should work for url with fragments', () => { | ||
expect(isUrlPathContain('/a/b#fragment', '/a/b')).toBeTruthy(); | ||
}); | ||
|
||
it('isUrlPathContain should work for url with query strings', () => { | ||
expect(isUrlPathContain('/a/b?a=1;b=2&c=3', '/a/b')).toBeTruthy(); | ||
}); | ||
|
||
it('isUrlPathEqual should work for identical paths', () => { | ||
expect(isUrlPathEqual('/a/b/c', '/a/b')).toBeFalsy(); | ||
expect(isUrlPathEqual('/a/b/c', '/a/b/c')).toBeTruthy(); | ||
}); | ||
|
||
it('isUrlPathEqual should work for url with fragments', () => { | ||
expect(isUrlPathEqual('/a/b/c#fragment', '/a/b/c')).toBeTruthy(); | ||
}); | ||
|
||
it('isUrlPathEqual should work for url with query strings', () => { | ||
expect(isUrlPathEqual('/a/b/c?a=1;b=2&c=3', '/a/b/c')).toBeTruthy(); | ||
}); | ||
|
||
}) | ||
|
||
|
21 changes: 21 additions & 0 deletions
21
src/framework/theme/components/menu/url-matching-helpers.ts
This file contains 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,21 @@ | ||
/** | ||
* @license | ||
* Copyright Akveo. All Rights Reserved. | ||
* Licensed under the MIT License. See License.txt in the project root for license information. | ||
*/ | ||
|
||
export function isUrlPathEqual(path, link) { | ||
const locationPath = getPathPartOfUrl(path); | ||
return link === locationPath; | ||
} | ||
|
||
export function isUrlPathContain(path, link) { | ||
const locationPath = getPathPartOfUrl(path); | ||
const endOfUrlSegmentRegExp = /\/|^$/; | ||
return locationPath.startsWith(link) && | ||
locationPath.slice(link.length).charAt(0).search(endOfUrlSegmentRegExp) !== -1; | ||
} | ||
|
||
function getPathPartOfUrl(url): string { | ||
return url.match(/.*?(?=[?#]|$)/)[0]; | ||
} |