Skip to content
Permalink
Browse files

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
  • Loading branch information
mrLarbi authored and gkalpak committed Sep 23, 2016
1 parent 2325e84 commit f8cc402d93f01c257f30f9db38e4590f233103b9
Showing with 14 additions and 1 deletion.
  1. +2 −1 src/ng/anchorScroll.js
  2. +12 −0 test/ng/anchorScrollSpec.js
@@ -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')));
});
});

0 comments on commit f8cc402

Please sign in to comment.
You can’t perform that action at this time.