Skip to content

Commit

Permalink
FIXED: Fix an issue where the first item in a newly inserted icon lis…
Browse files Browse the repository at this point in the history
…t would not be editable
  • Loading branch information
vmasto committed Nov 8, 2023
1 parent 466753c commit 15ac749
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 4 deletions.
2 changes: 1 addition & 1 deletion build/gutenbee.build.js

Large diffs are not rendered by default.

24 changes: 21 additions & 3 deletions src/blocks/icon-list/icon-list-item/edit.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Fragment, useRef } from 'wp.element';
import { Fragment, useRef, useEffect } from 'wp.element';
import { __ } from 'wp.i18n';
import { RichText, InspectorControls } from 'wp.blockEditor';
import {
Expand All @@ -11,6 +11,7 @@ import classNames from 'classnames';
import { createBlock } from 'wp.blocks';
import ReactSelect from 'react-select';
import startCase from 'lodash.startcase';
import { useSelect } from 'wp.data';

import Icon from './Icon';
import icons from '../../icon/icons';
Expand All @@ -23,14 +24,32 @@ const IconListItemEdit = ({
setAttributes,
onReplace,
isSelected,
clientId,
}) => {
const { content, icon, listUrl, newTab } = attributes;
const ref = useRef();
const richTextRef = useRef();

const isParentSelected = useSelect(
select => {
const { getBlockParents, isBlockSelected } = select('core/block-editor');
const [parentBlockId] = getBlockParents(clientId);
return isBlockSelected(parentBlockId);
},
[clientId],
);

useEffect(() => {
if (richTextRef.current && isParentSelected) {
richTextRef.current.focus();
}
}, [richTextRef.current, isParentSelected]);

const listItem = (
<Fragment>
<Icon className={className} {...attributes} />
<RichText
ref={richTextRef}
identifier="content"
tagName="div"
className={classNames(
Expand All @@ -40,9 +59,8 @@ const IconListItemEdit = ({
value={content}
aria-label={__('Icon List Item block')}
placeholder={__('Start writing…')}
keepPlaceholderOnFocus={true}
multiline={false}
disableLineBreaks={true}
disableLineBreaks
onChange={content => setAttributes({ content })}
onReplace={onReplace}
onSplit={value => {
Expand Down

0 comments on commit 15ac749

Please sign in to comment.