| 1 |
import React, { useEffect } from 'react' |
| 2 |
|
| 3 |
const SLOT_ID = 'snippets-screen-meta-slot' |
| 4 |
|
| 5 |
/** |
| 6 |
* Relocates the WordPress Screen Options and Help tabs (and their panels) |
| 7 |
* from above the page content into this slot, so they appear directly below |
| 8 |
* the page's subnavigation bar. The slot div is rendered empty by React and |
| 9 |
* never reconciled with children, so adopting the foreign nodes is safe. |
| 10 |
* The nodes are returned to the top of the page when the slot unmounts. |
| 11 |
*/ |
| 12 |
export const ScreenMetaSlot: React.FC = () => { |
| 13 |
useEffect(() => { |
| 14 |
const slot = document.getElementById(SLOT_ID) |
| 15 |
const meta = document.getElementById('screen-meta') |
| 16 |
const links = document.getElementById('screen-meta-links') |
| 17 |
|
| 18 |
if (!slot || !meta || !links) { |
| 19 |
return undefined |
| 20 |
} |
| 21 |
|
| 22 |
const parent = meta.parentElement |
| 23 |
slot.append(meta, links) |
| 24 |
|
| 25 |
return () => { |
| 26 |
parent?.prepend(meta, links) |
| 27 |
} |
| 28 |
}, []) |
| 29 |
|
| 30 |
return <div id={SLOT_ID} className="snippets-screen-meta-slot" /> |
| 31 |
} |
| 32 |
|