PluginProbe
User Profile Builder – Beautiful User Registration Forms, User Profiles & User Role Editor / 4.0.3
User Profile Builder – Beautiful User Registration Forms, User Profiles & User Role Editor v4.0.3
4.0.3 4.0.2 4.0.1 4.0.0 3.16.6 3.16.5 3.16.4 3.16.3 3.16.2 3.16.1 3.16.0 3.15.9 3.9.9 3.9.5 3.9.6 3.9.7 3.9.8 1.1.7 1.1.8 1.1.9 2.0.2 2.0.3 2.0.4 2.0.5 2.0.6 All 341 releases
profile-builder / form-builder / blocks / src / components / DisableDocumentBar.js

DisableDocumentBar.js in User Profile Builder – Beautiful User Registration Forms, User Profiles & User Role Editor 4.0.3, at form-builder/blocks/src/components/DisableDocumentBar.js

41 lines 1.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 /**
2 * Drop the document-bar title button from the tab order on PB form CPTs (Layer 12).
3 * CSS already blocks pointer events; MutationObserver re-applies tabindex="-1".
4 */
5
6 import { useEffect } from '@wordpress/element';
7 import { useSelect } from '@wordpress/data';
8 import { registerPlugin } from '@wordpress/plugins';
9
10 const PB_CPTS = [ 'wppb-rf-cpt', 'wppb-epf-cpt' ];
11 const COMMAND_SELECTOR = '.editor-document-bar__command';
12
13 const applyTabIndex = () => {
14 const btn = document.querySelector( COMMAND_SELECTOR );
15 if ( btn && btn.getAttribute( 'tabindex' ) !== '-1' ) {
16 btn.setAttribute( 'tabindex', '-1' );
17 }
18 };
19
20 const DisableDocumentBar = () => {
21 const postType = useSelect(
22 ( select ) => select( 'core/editor' ).getCurrentPostType(),
23 []
24 );
25 const isOurPostType = PB_CPTS.includes( postType );
26
27 useEffect( () => {
28 if ( ! isOurPostType ) return undefined;
29
30 applyTabIndex();
31
32 const observer = new MutationObserver( applyTabIndex );
33 observer.observe( document.body, { childList: true, subtree: true } );
34 return () => observer.disconnect();
35 }, [ isOurPostType ] );
36
37 return null;
38 };
39
40 registerPlugin( 'wppb-fb-disable-document-bar', { render: DisableDocumentBar } );
41