Skip to content
Merged
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
15 changes: 6 additions & 9 deletions inc/render.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,24 +112,21 @@ static function ( array $matches ) use ( $icon, $position ): string {
* front end is the raw comment JSON, never merged against registered
* defaults — see the file docblock in `inc/attributes.php`. So an explicit
* `'hidden'` or an explicit `'mobile'` always wins, and a `'visible'` only
* counts once the legacy flag is confirmed clear; otherwise the legacy flag
* decides, exactly as it did before this attribute existed.
* counts once the legacy flag is confirmed clear. Otherwise the legacy flag
* decides, exactly as it did before this attribute existed. A value outside
* the enum is treated as absent, so it never hides a label by itself.
*
* @param array $attributes The block's attributes.
* @return string One of 'visible', 'mobile', 'hidden'.
*/
function label_visibility( array $attributes ): string {
$visibility = $attributes['hmLabelVisibility'] ?? 'visible';

if ( 'hidden' === $visibility ) {
return 'hidden';
if ( in_array( $visibility, [ 'hidden', 'mobile' ], true ) ) {
return $visibility;
}

if ( 'visible' === $visibility && empty( $attributes['hmHideLabelOnMobile'] ) ) {
return 'visible';
}

return 'mobile';
return empty( $attributes['hmHideLabelOnMobile'] ) ? 'visible' : 'mobile';
}

/**
Expand Down
10 changes: 3 additions & 7 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,15 +80,11 @@ const NO_ICON = {
function resolveLabelVisibility( attributes ) {
const { hmLabelVisibility, hmHideLabelOnMobile } = attributes;

if ( 'hidden' === hmLabelVisibility ) {
return 'hidden';
if ( [ 'hidden', 'mobile' ].includes( hmLabelVisibility ) ) {
return hmLabelVisibility;
}

if ( 'visible' === hmLabelVisibility && ! hmHideLabelOnMobile ) {
return 'visible';
}

return 'mobile';
return hmHideLabelOnMobile ? 'mobile' : 'visible';
}

/**
Expand Down
Loading