Skip to content
Prev Previous commit
Next Next commit
Small code quality tweaks
  • Loading branch information
andrewserong committed Jun 16, 2023
commit 5ad63a240fa8809efb825772c073640890733217
8 changes: 4 additions & 4 deletions packages/block-editor/src/hooks/position.js
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ export function PositionPanel( props ) {

const blockInformation = useBlockDisplayInformation( firstParentClientId );
Copy link
Contributor

Choose a reason for hiding this comment

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

Crazy idea: could we use this client id to instead inject a style in the DOM like #block-clientid :has(.ist-sticky.is-selected) { outline: 1px solid grey} or whatever?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh, that is a clever idea — I can't remember why exactly, but I think from memory there was a preference to try to use popovers so that we don't accidentally collide with any styles that a theme might have for a particular block. It could be to ensure that the visualizers / popover always displays its CSS styling in addition to whatever might be set on the parent block (that we can't quite know) rather than overriding anything. Worth playing with though!

Copy link
Contributor

Choose a reason for hiding this comment

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

I picked outline because it's very unlikely that it gets used for block styling, as it's mostly a property applied on focus. Though if the popover calculations are performant I suppose it's not really an issue.

const stickyHelpText =
allowSticky && value === 'sticky' && blockInformation
allowSticky && value === STICKY_OPTION.value && blockInformation
? sprintf(
/* translators: %s: the name of the parent block. */
__(
Expand All @@ -302,8 +302,8 @@ export function PositionPanel( props ) {

const options = useMemo( () => {
const availableOptions = [ DEFAULT_OPTION ];
// Only display sticky option if the block has no parents (is at the root of the document),
// or if the block already has a sticky position value set.
// Display options if they are allowed, or if a block already has a valid value set.
// This allows for a block to be switched off from a position type that is not allowed.
if ( allowSticky || value === STICKY_OPTION.value ) {
availableOptions.push( STICKY_OPTION );
}
Expand Down Expand Up @@ -345,7 +345,7 @@ export function PositionPanel( props ) {
web:
options.length > 1 ? (
<InspectorControls group="position">
{ firstParentClientId && value === 'sticky' ? (
{ firstParentClientId && value === STICKY_OPTION.value ? (
<PositionVisualizer
forceShow={ isSelected }
{ ...props }
Expand Down