diff --git a/inc/render.php b/inc/render.php index 94c51a5..2fefda3 100644 --- a/inc/render.php +++ b/inc/render.php @@ -112,8 +112,9 @@ 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'. @@ -121,15 +122,11 @@ static function ( array $matches ) use ( $icon, $position ): string { 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'; } /** diff --git a/src/index.js b/src/index.js index 1c757eb..5cfe8c7 100644 --- a/src/index.js +++ b/src/index.js @@ -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'; } /**