Problem/Motivation
When styling blocks using div.block:nth-of-type()
blocks will look correct in the frontend, but when viewed in layout builder there is an off by 1 error. Meaning block 1 has the styling of block 2, and so on.
This occurs because :nth-of-type()
only considers that the block is a div
, not that is has a class of block
. On the layout builder an additional region label div
is injected above the blocks. Generally this label is not seen, but appears when in "move mode".
Steps to reproduce
- Add
div.block:nth-of-type()
css
- Observe it looks correct when viewed normally
- Enter layout builder
- Observe block styling is off by 1
Proposed resolution
Suggest that the region label can use a alternative tag than div
.
e.g.
LayoutBuilder.php
<snip>
// The region label is made visible when the move block dialog is open.
$build[$region]['region_label'] = [
- '#type' => 'container',
+ '#type' => 'html_tag',
+ '#tag' => 'p',
'#attributes' => [
'class' => ['layout__region-info', 'layout-builder__region-label'],
// A more detailed version of this information is already read by
// screen readers, so this label can be hidden from them.
'aria-hidden' => TRUE,
],
- '#markup' => $this->t('Region: @region', ['@region' => $info['label']]),
+ '#value' => $this->t('Region: @region', ['@region' => $info['label']]),
// Ensures the region label is displayed first.
'#weight' => min($weights) - 1,
];
}
<snip>
Remaining tasks
- Decide best course of action for resolution
- Do it
User interface changes
- Block appears correctly in layout builder when styled with
:nth-of-type()
API changes
Data model changes
Release notes snippet
TBD