Skip to content

Commit

Permalink
Interactivity API: Remove wp-data-navigation-link directive (#57853)
Browse files Browse the repository at this point in the history
* Remove wp-data-navigation-link directive

* Update changelog

* Remove not needed functions

* Revert "Remove not needed functions"

This reverts commit 3461c772474e42ca89785fa9b302dbd85ff43b0c.

* Move breaking change changelog to correct position

* Add function style to changelog
  • Loading branch information
cbravobernal authored Jan 16, 2024
1 parent b8ecb81 commit fc85022
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 50 deletions.
1 change: 1 addition & 0 deletions packages/interactivity/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
### Breaking Change

- Remove `data-wp-slot` and `data-wp-fill`. ([#57854](https://github.com/WordPress/gutenberg/pull/57854))
- Remove `wp-data-navigation-link` directive. ([#57853](https://github.com/WordPress/gutenberg/pull/57853))

### Bug Fix

Expand Down
51 changes: 1 addition & 50 deletions packages/interactivity/src/directives.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,7 @@
/**
* External dependencies
*/
import {
useContext,
useMemo,
useEffect,
useRef,
useLayoutEffect,
} from 'preact/hooks';
import { useContext, useMemo, useRef, useLayoutEffect } from 'preact/hooks';
import { deepSignal, peek } from 'deepsignal';

/**
Expand All @@ -16,7 +10,6 @@ import { deepSignal, peek } from 'deepsignal';
import { createPortal } from './portals';
import { useWatch, useInit } from './utils';
import { directive } from './hooks';
import { navigate } from './router';

const isObject = ( item ) =>
item && typeof item === 'object' && ! Array.isArray( item );
Expand Down Expand Up @@ -264,48 +257,6 @@ export default () => {
);
} );

// data-wp-navigation-link
directive(
'navigation-link',
( {
directives: { 'navigation-link': navigationLink },
props: { href },
element,
} ) => {
const { value: link } = navigationLink.find(
( { suffix } ) => suffix === 'default'
);

useEffect( () => {
// Prefetch the page if it is in the directive options.
if ( link?.prefetch ) {
// prefetch( href );
}
} );

// Don't do anything if it's falsy.
if ( link !== false ) {
element.props.onclick = async ( event ) => {
event.preventDefault();

// Fetch the page (or return it from cache).
await navigate( href );

// Update the scroll, depending on the option. True by default.
if ( link?.scroll === 'smooth' ) {
window.scrollTo( {
top: 0,
left: 0,
behavior: 'smooth',
} );
} else if ( link?.scroll !== false ) {
window.scrollTo( 0, 0 );
}
};
}
}
);

// data-wp-ignore
directive(
'ignore',
Expand Down

0 comments on commit fc85022

Please sign in to comment.