Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make tabs header editable #1869

Merged
merged 2 commits into from
Sep 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 18 additions & 15 deletions src/blocks/blocks/tabs/editor.scss
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,12 @@
.wp-block-themeisle-blocks-tabs__header_item + div {
margin-bottom: calc(0px - var(--border-side-width));
}

.wp-block-themeisle-blocks-tabs__header_item {

* {
cursor: text;
}

svg {
fill: gray;
max-width: 24px;
Expand All @@ -39,7 +42,7 @@
margin-bottom: 0px;
}

&> .block-editor-block-list__block {
&> .block-editor-block-list__block {
border-color: inherit;
&:not(:last-of-type) {
&> .wp-block-themeisle-blocks-tabs-item__header {
Expand Down Expand Up @@ -70,10 +73,10 @@
.wp-block-themeisle-blocks-tabs__content {
> .block-editor-inner-blocks {
height: 100%;

> .block-editor-block-list__layout {
height: 100%;

> .block-editor-block-list__block {
&:has( > .wp-block-themeisle-blocks-tabs-item__content.active) {
@media (min-width: 800px) {
Expand All @@ -84,7 +87,7 @@
}
}
}
}
}

// &.is-style-boxed > .wp-block-themeisle-blocks-tabs__content {
// &> .block-editor-inner-blocks {
Expand All @@ -110,26 +113,26 @@
border-left-width: 0px;
border-top-width: 0px;
border-right-width: 0px;

&:not(.active) {
border-bottom-color: transparent;
}

&.active {
border-bottom-style: solid;
border-color: var(--active-title-border-color);
}
}

&> .wp-block-themeisle-blocks-tabs-item__content {
border-left-width: 0px;
border-right-width: 0px;

@media (max-width: 800px) {
border-top-width: 0px;
border-bottom-width: 0px;
}

@media (min-width: 800px) {
border-bottom-width: 0px;
}
Expand All @@ -147,14 +150,14 @@
@media (max-width: 800px) {
flex-direction: column;
}


&> .wp-block-themeisle-blocks-tabs-item__content {
flex-grow: 1;
}
}
}

.add-header-container {
display: flex;
align-items: center;
Expand All @@ -167,11 +170,11 @@
z-index: 10;
}
}

&.has-pos-left {
.add-header-container {
height: 30px;

&> .add-header-item > button {
left: 0px;
bottom: -10px;
Expand Down
23 changes: 18 additions & 5 deletions src/blocks/blocks/tabs/group/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,14 @@ import { createBlock } from '@wordpress/blocks';

import {
InnerBlocks,
RichText,
useBlockProps
} from '@wordpress/block-editor';

import {
useSelect,
useDispatch
useDispatch,
dispatch
} from '@wordpress/data';

import {
Expand All @@ -34,7 +36,7 @@ import metadata from './block.json';
import Inspector from './inspector.js';
import Controls from './controls.js';
import { blockInit, getDefaultValueByField } from '../../../helpers/block-utility.js';
import { boxToCSS, objectOrNumberAsBox, _i, _px } from '../../../helpers/helper-functions';
import { boxToCSS, objectOrNumberAsBox, _px } from '../../../helpers/helper-functions';
import classNames from 'classnames';
import BlockAppender from '../../../components/block-appender-button';
import { useDarkBackground } from '../../../helpers/utility-hooks.js';
Expand All @@ -45,7 +47,8 @@ const TabHeader = ({
tag,
title,
onClick,
active
active,
onChangeTitle
}) => {
const CustomTag = tag ?? 'div';
return (
Expand All @@ -58,7 +61,14 @@ const TabHeader = ({
) }
onClick={ onClick }
>
<CustomTag >{ title }</CustomTag>
<RichText
placeholder={ __( 'Add title…', 'otter-blocks' ) }
value={ title }
onChange={ onChangeTitle }
tagName={ tag ?? 'div' }
withoutInteractiveFormatting
multiline={ false }
/>
</div>
);
};
Expand Down Expand Up @@ -251,9 +261,12 @@ const Edit = ({
<TabHeader
key={ tabHeader.clientId }
tag={ attributes.titleTag }
title={ tabHeader.attributes.title ?? `${__( 'Tab', 'otter-blocks' )} ${idx + 1}` }
title={ tabHeader.attributes?.title ?? `${__( 'Tab', 'otter-blocks' )} ${idx + 1}` }
active={ tabHeader.clientId === activeTab }
onClick={ () => toggleActiveTab( tabHeader.clientId ) }
onChangeTitle={ value => {
dispatch( 'core/block-editor' ).updateBlockAttributes( tabHeader.clientId, { title: value.replace( /(\r\n|\n|\r|<br>)/gm, '' ) });
}}
/>
);
}) || '' }
Expand Down
10 changes: 10 additions & 0 deletions src/blocks/test/e2e/blocks/tabs.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,4 +68,14 @@ test.describe( 'Tabs Block', () => {

expect( await page.getByRole( 'paragraph' ).filter({ hasText: 'This is just a placeholder to help you visualize how the content is displayed in' }).isVisible() ).toBeTruthy();
});

test( 'change tab header content', async({ editor, page }) => {
await editor.insertBlock({
name: 'themeisle-blocks/tabs'
});

await page.getByRole( 'textbox', { name: 'Add title…' }).first().fill( 'Tab 1000' );

await expect( page.locator( 'div' ).filter({ hasText: /^Tab 1000$/ }).first() ).toBeVisible();
});
});
Loading