feat($anchorScroll): convert numeric hash targets to string
This allows `$anchorScroll(7)` to scroll to `<div id="7">` (although technically, the target ID is a string, not a number). Fixes #14680 Closes #15182
This commit is contained in:
committed by
Georgios Kalpakas
parent
3253b55861
commit
9062bae05c
@@ -238,7 +238,8 @@ function $AnchorScrollProvider() {
|
||||
}
|
||||
|
||||
function scroll(hash) {
|
||||
hash = isString(hash) ? hash : $location.hash();
|
||||
// Allow numeric hashes
|
||||
hash = isString(hash) ? hash : isNumber(hash) ? hash.toString() : $location.hash();
|
||||
var elm;
|
||||
|
||||
// empty hash, scroll to the top of the page
|
||||
|
||||
@@ -260,6 +260,18 @@ describe('$anchorScroll', function() {
|
||||
addElements('id=top'),
|
||||
callAnchorScroll('top'),
|
||||
expectScrollingTo('id=top')));
|
||||
|
||||
|
||||
it('should scroll to element with id "7" if present, with a given hash of type number', inject(
|
||||
addElements('id=7'),
|
||||
callAnchorScroll(7),
|
||||
expectScrollingTo('id=7')));
|
||||
|
||||
|
||||
it('should scroll to element with id "7" if present, with a given hash of type string', inject(
|
||||
addElements('id=7'),
|
||||
callAnchorScroll('7'),
|
||||
expectScrollingTo('id=7')));
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user