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

Nav block: remove list markup #31827

Closed
wants to merge 1 commit into from
Closed
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
4 changes: 2 additions & 2 deletions packages/block-library/src/home-link/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export default function HomeEdit( {

return (
<>
<li { ...blockProps }>
<div { ...blockProps }>
<a
className="wp-block-home-link__content"
href={ homeUrl }
Expand All @@ -80,7 +80,7 @@ export default function HomeEdit( {
] }
/>
</a>
</li>
</div>
</>
);
}
4 changes: 2 additions & 2 deletions packages/block-library/src/home-link/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ function render_block_core_home_link( $attributes, $content, $block ) {

$wrapper_attributes = block_core_home_link_build_li_wrapper_attributes( $block->context );

$html = '<li ' . $wrapper_attributes . '><a class="wp-block-home-link__content"';
$html = '<div ' . $wrapper_attributes . '><a class="wp-block-home-link__content"';

// Start appending HTML attributes to anchor tag.
$html .= ' href="' . esc_url( home_url() ) . '"';
Expand Down Expand Up @@ -157,7 +157,7 @@ function render_block_core_home_link( $attributes, $content, $block ) {
);
}

$html .= '</a></li>';
$html .= '</a></div>';
return $html;
}

Expand Down
6 changes: 3 additions & 3 deletions packages/block-library/src/navigation-link/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -507,7 +507,7 @@ export default function NavigationLinkEdit( {
/>
</PanelBody>
</InspectorControls>
<li { ...blockProps }>
<div { ...blockProps }>
{ /* eslint-disable jsx-a11y/anchor-is-valid */ }
<a className={ classes }>
{ /* eslint-enable */ }
Expand Down Expand Up @@ -611,8 +611,8 @@ export default function NavigationLinkEdit( {
<ItemSubmenuIcon />
</span>
) }
<ul { ...innerBlocksProps } />
</li>
<div { ...innerBlocksProps } />
</div>
</Fragment>
);
}
6 changes: 3 additions & 3 deletions packages/block-library/src/navigation-link/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ function render_block_core_navigation_link( $attributes, $content, $block ) {
'style' => $style_attribute,
)
);
$html = '<li ' . $wrapper_attributes . '>' .
$html = '<div ' . $wrapper_attributes . '>' .
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Following this line of thinking, I think it should be possible to drop this div wrapper too here in navigation-link and home-link.

This change would need to rework the css for how submenus work, of course.

This is non blocking since changes here work well and now markup validates properly, but I think it'd be worth exploring.

Example before Example after
Screen Shot 2021-05-14 at 10 10 14 AM Screen Shot 2021-05-14 at 10 24 46 AM

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Definitely, but I didn't want to touch the styling as part of this PR. :)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, this could be done as a follow up too if we choose this approach 👍

'<a class="wp-block-navigation-link__content" ';

// Start appending HTML attributes to anchor tag.
Expand Down Expand Up @@ -214,12 +214,12 @@ function render_block_core_navigation_link( $attributes, $content, $block ) {
}

$html .= sprintf(
'<ul class="wp-block-navigation-link__container">%s</ul>',
'<div class="wp-block-navigation-link__container">%s</div>',
$inner_blocks_html
);
}

$html .= '</li>';
$html .= '</div>';

return $html;
}
Expand Down
11 changes: 0 additions & 11 deletions packages/block-library/src/navigation/editor.scss
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,6 @@
* Editor only CSS.
*/

// Undo default editor styles.
// These need extra specificity.
.editor-styles-wrapper .wp-block-navigation {
ul {
margin-top: 0;
margin-bottom: 0;
margin-left: 0;
padding-left: 0;
}
}


/**
* Submenus.
Expand Down
4 changes: 2 additions & 2 deletions packages/block-library/src/navigation/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ function render_block_core_navigation( $attributes, $content, $block ) {
// return early if they don't.
if ( ! isset( $attributes['isResponsive'] ) || false === $attributes['isResponsive'] ) {
return sprintf(
'<nav %1$s><ul class="wp-block-navigation__container">%2$s</ul></nav>',
'<nav %1$s><div class="wp-block-navigation__container">%2$s</div></nav>',
$wrapper_attributes,
$inner_blocks_html
);
Expand All @@ -179,7 +179,7 @@ function render_block_core_navigation( $attributes, $content, $block ) {
<div class="wp-block-navigation__responsive-dialog" role="dialog" aria-modal="true" aria-labelledby="modal-%1$s-title" >
<button aria-label="%4$s" data-micromodal-close class="wp-block-navigation__responsive-container-close"><svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" width="24" height="24" role="img" aria-hidden="true" focusable="false"><path d="M13 11.8l6.1-6.3-1-1-6.1 6.2-6.1-6.2-1 1 6.1 6.3-6.5 6.7 1 1 6.5-6.6 6.5 6.6 1-1z"></path></svg></button>
<div class="wp-block-navigation__responsive-container-content" id="modal-%1$s-content">
<ul class="wp-block-navigation__container">%2$s</ul>
<div class="wp-block-navigation__container">%2$s</div>
</div>
</div>
</div>
Expand Down
17 changes: 2 additions & 15 deletions packages/block-library/src/navigation/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,6 @@
// Page List block inside your navigation block.
.wp-block-navigation {
position: relative;
// Normalize list styles.
ul,
ul li {
list-style: none;

// Overrides generic ".entry-content li" styles on the front end.
padding: 0;
}

// Menu item container.
.wp-block-pages-list__item,
Expand Down Expand Up @@ -299,11 +291,6 @@
// Vertically center child blocks, like Social Links or Search.
align-items: center;

// Reset the default list styles
list-style: none;
margin: 0;
padding-left: 0;

// Only hide the menu by default if responsiveness is active.
.is-responsive {
display: none;
Expand Down Expand Up @@ -338,11 +325,11 @@
}

// Vertical justification.
.is-vertical.items-justified-center > ul {
.is-vertical.items-justified-center > div {
align-items: center;
}

.is-vertical.items-justified-right > ul {
.is-vertical.items-justified-right > div {
align-items: flex-end;

.wp-block-navigation-link,
Expand Down
8 changes: 4 additions & 4 deletions packages/block-library/src/page-list/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,16 +102,16 @@ function render_nested_page_list( $nested_pages ) {
if ( isset( $page['children'] ) ) {
$css_class .= ' has-child';
}
$markup .= '<li class="' . $css_class . '">';
$markup .= '<div class="' . $css_class . '">';
$markup .= '<a class="wp-block-pages-list__item__link" href="' . esc_url( $page['link'] ) . '">' . wp_kses(
$page['title'],
wp_kses_allowed_html( 'post' )
) . '</a>';
if ( isset( $page['children'] ) ) {
$markup .= '<span class="wp-block-page-list__submenu-icon"><svg xmlns="http://www.w3.org/2000/svg" width="12" height="12" viewBox="0 0 12 12" fill="none" role="img" aria-hidden="true" focusable="false"><path d="M1.50002 4L6.00002 8L10.5 4" stroke-width="1.5"></path></svg></span>';
$markup .= '<ul class="submenu-container">' . render_nested_page_list( $page['children'] ) . '</ul>';
$markup .= '<div class="submenu-container">' . render_nested_page_list( $page['children'] ) . '</div>';
}
$markup .= '</li>';
$markup .= '</div>';
}
return $markup;
}
Expand Down Expand Up @@ -182,7 +182,7 @@ function render_block_core_page_list( $attributes, $content, $block ) {

$nested_pages = nest_pages( $top_level_pages, $pages_with_children );

$wrapper_markup = '<ul %1$s>%2$s</ul>';
$wrapper_markup = '<div %1$s>%2$s</div>';

$items_markup = render_nested_page_list( $nested_pages );

Expand Down