Setting up TabPanel in custom block
-
I’m sure this is a noob question, but I could really use some help. I’m building a custom block and started with the @wordpress/create-block scaffolding. I need the block to display some tabbed data in both the block editor and on the published page. I found the TabPanel component in the documentation, and it seems to be perfect for what I’m looking for. I can get the tabs to appear and function just fine in the block editor, but I can’t figure out how to get it to show on the published page. I’m new to React, so a shove in the right direction would be most helpful.
My edit.js file:
import { useBlockProps } from '@wordpress/block-editor'; import { TabPanel } from '@wordpress/components'; export default function Edit({ attributes, setAttributes, isSelected, className }) { const onSelect = (tabName) => { console.log('Selecting tab', tabName); }; const blockProps = useBlockProps(); const MyTabPanel = () => ( <TabPanel className="my-tab-panel" activeClass="active-tab" onSelect={onSelect} tabs={[ { name: 'tab1', title: 'Tab 1', className: 'tab-one', }, { name: 'tab2', title: 'Tab 2', className: 'tab-two', }, ]} > {(tab) => <p>{tab.title}</p>} </TabPanel> ); return ( <div {...blockProps} > {MyTabPanel()} </div> ) }Can someone show me what the save.js file should look like so that the tabbed component will display on the front end of the site?
The topic ‘Setting up TabPanel in custom block’ is closed to new replies.