Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

Commit 9062bae

Browse files
mrLarbigkalpak
authored andcommitted
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
1 parent 3253b55 commit 9062bae

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

src/ng/anchorScroll.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,8 @@ function $AnchorScrollProvider() {
238238
}
239239

240240
function scroll(hash) {
241-
hash = isString(hash) ? hash : $location.hash();
241+
// Allow numeric hashes
242+
hash = isString(hash) ? hash : isNumber(hash) ? hash.toString() : $location.hash();
242243
var elm;
243244

244245
// empty hash, scroll to the top of the page

test/ng/anchorScrollSpec.js

+12
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,18 @@ describe('$anchorScroll', function() {
260260
addElements('id=top'),
261261
callAnchorScroll('top'),
262262
expectScrollingTo('id=top')));
263+
264+
265+
it('should scroll to element with id "7" if present, with a given hash of type number', inject(
266+
addElements('id=7'),
267+
callAnchorScroll(7),
268+
expectScrollingTo('id=7')));
269+
270+
271+
it('should scroll to element with id "7" if present, with a given hash of type string', inject(
272+
addElements('id=7'),
273+
callAnchorScroll('7'),
274+
expectScrollingTo('id=7')));
263275
});
264276
});
265277

0 commit comments

Comments
 (0)