Skip to content

Commit

Permalink
Add the hashCloak option to AnchorScrollTo
Browse files Browse the repository at this point in the history
  • Loading branch information
antoine4livre committed Mar 27, 2024
1 parent 7e6c2f0 commit f99e5e1
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions packages/ui/atoms/AnchorScrollTo/AnchorScrollTo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ export interface AnchorScrollToProps extends BaseProps {
export class AnchorScrollTo<T extends BaseProps = BaseProps> extends Base<AnchorScrollToProps & T> {
static config: BaseConfig = {
name: 'AnchorScrollTo',
options: {
hashCloak: Boolean,
},
};

/**
Expand All @@ -27,10 +30,21 @@ export class AnchorScrollTo<T extends BaseProps = BaseProps> extends Base<Anchor
* @param {MouseEvent} event
* @returns {void}
*/
onClick(event) {
async onClick(event) {
const target = document.querySelector(this.targetSelector) as HTMLElement;

Check warning on line 34 in packages/ui/atoms/AnchorScrollTo/AnchorScrollTo.ts

View check run for this annotation

Codecov / codecov/patch

packages/ui/atoms/AnchorScrollTo/AnchorScrollTo.ts#L33-L34

Added lines #L33 - L34 were not covered by tests
if (!target) {
return;

Check warning on line 36 in packages/ui/atoms/AnchorScrollTo/AnchorScrollTo.ts

View check run for this annotation

Codecov / codecov/patch

packages/ui/atoms/AnchorScrollTo/AnchorScrollTo.ts#L36

Added line #L36 was not covered by tests
}

try {
scrollTo(this.targetSelector);
event.preventDefault();
await scrollTo(target);

Check warning on line 41 in packages/ui/atoms/AnchorScrollTo/AnchorScrollTo.ts

View check run for this annotation

Codecov / codecov/patch

packages/ui/atoms/AnchorScrollTo/AnchorScrollTo.ts#L41

Added line #L41 was not covered by tests

if (this.$options.hashCloak) {
return;

Check warning on line 44 in packages/ui/atoms/AnchorScrollTo/AnchorScrollTo.ts

View check run for this annotation

Codecov / codecov/patch

packages/ui/atoms/AnchorScrollTo/AnchorScrollTo.ts#L44

Added line #L44 was not covered by tests
}

window.location.hash = this.targetSelector;

Check warning on line 47 in packages/ui/atoms/AnchorScrollTo/AnchorScrollTo.ts

View check run for this annotation

Codecov / codecov/patch

packages/ui/atoms/AnchorScrollTo/AnchorScrollTo.ts#L47

Added line #L47 was not covered by tests
} catch {
// Silence is golden.
}
Expand Down

0 comments on commit f99e5e1

Please sign in to comment.