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

List block - Cannot delete last empty list item #12787

Closed
bobbingwide opened this issue Dec 11, 2018 · 8 comments
Closed

List block - Cannot delete last empty list item #12787

bobbingwide opened this issue Dec 11, 2018 · 8 comments
Assignees
Labels
[Block] List Affects the List Block Needs Testing Needs further testing to be confirmed.

Comments

@bobbingwide
Copy link
Contributor

Describe the bug
I had a list block with an empty item as the last item. When I deleted the item the bullet disappeared. But the <li></li> tags didn't. So, after update, the empty item reappeared.

Workarounds...

  • Use the code editor to remove the empty item.
  • Click on the indent/outdent buttons.

To Reproduce
Steps to reproduce the behavior:

  1. Create a List block with an empty item
  2. Save, view and edit
  3. Attempt to delete the empty item using the Delete key
  4. The bullet disappears
  5. But switch to ordered and see the empty item reappear.

Expected behavior
The empty <li></li> should be deleted.

Screenshots
If applicable, add screenshots to help explain your problem.
image

Desktop (please complete the following information):

  • OS: Windows 10
  • Browser: Chrome

Smartphone (please complete the following information):

  • Device: [e.g. iPhone6]
  • OS: [e.g. iOS8.1]
  • Browser [e.g. stock browser, safari]
  • Version [e.g. 22]

Additional context

  • Gutenberg 4.6.1
@swissspidy swissspidy added Needs Testing Needs further testing to be confirmed. [Block] List Affects the List Block labels Dec 11, 2018
@skorasaurus
Copy link
Member

Confirmed this also occurs in WordPress 5.1-alpha-43678

@chthonic-ds
Copy link
Contributor

Can confirm this happens in WordPress 5.0.2, same desktop specs as OP.

@kadamwhite
Copy link
Contributor

kadamwhite commented Jan 3, 2019

This also happens in custom blocks when using a multiline RichText element:

// edit() method:
<RichText
	tagName="ul"
	multiline="li"
	value={ listItems }
	onChange={ listItems => setAttributes( { listItems } ) }
	placeholder={ __( 'Enter text here. Text may contain links.', 'project' ) }
/>

//save() method:
<RichText.Content
	tagName="ul"
	multiline="li"
	value={ listItems }
/>

Edit/Update: We resolved this for our custom elements by implementing a removeEmptyTrailingItems() method which we call on the list when passing listItems into setAttributes:

const removeEmptyTrailingItems = listItems => {
	if ( listItems.length === 1 ) {
		// Do not delete list entirely even if first element empty.
		return listItems;
	}
	const lastItem = listItems[ listItems.length - 1 ];
	if ( lastItem && lastItem.props && lastItem.props.children ) {
		if ( lastItem.props.children.length === 0 ) {
			// Recursively remove empty trailing list items.
			return removeEmptyTrailingItems( listItems.slice( 0, -1 ) );
		}
	}
	return listItems;
};

@youknowriad
Copy link
Contributor

Can't reproduce this anymore. I suspect it was fixed by #13697.

@ellatrix
Copy link
Member

Thanks for testing!

@kennethz3
Copy link

This issue has appeared again on my site

@kennethz3
Copy link

Scenario to reproduce:

  • Classic block before List block in a post
  • Classic block containing bullet list, and list block containing a few list items
  • Add a new list item at the end of the list in the classic block
  • New empty list item appears at the end of the list block

@timofey-drozhzhin
Copy link

Related issue #14977

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Block] List Affects the List Block Needs Testing Needs further testing to be confirmed.
Projects
None yet
Development

No branches or pull requests

9 participants