Skip to content

Commit f80a5e5

Browse files
fix: improve vertical alignment handling
1 parent 0de941c commit f80a5e5

1 file changed

Lines changed: 18 additions & 22 deletions

File tree

includes/front.php

Lines changed: 18 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,19 @@ final class Menu_Icons_Front_End {
5151
*/
5252
protected static $hidden_label_class = 'visuallyhidden';
5353

54+
/**
55+
* Align-self map for vertical-align values.
56+
*
57+
* @access private
58+
* @var array
59+
*/
60+
private static $align_self_map = array(
61+
'top' => 'flex-start',
62+
'middle' => 'center',
63+
'bottom' => 'flex-end',
64+
'baseline' => 'baseline',
65+
);
66+
5467

5568
/**
5669
* Add hooks for front-end functionalities
@@ -341,13 +354,13 @@ public static function get_icon_style( $meta, $keys, $as_attribute = true ) {
341354

342355
// Special handling for vertical-align because it affects the layout of flex containers.
343356
if ( 'vertical_align' === $key ) {
344-
$stored = isset( $meta[ $key ] ) ? $meta[ $key ] : $rule['value'];
345-
346-
if ( $stored !== $rule['value'] ) {
347-
$style_a[ $rule['property'] ] = $stored;
357+
if ( ! isset( $meta[ $key ] ) || $meta[ $key ] === $rule['value'] ) {
358+
continue;
348359
}
349360

350-
$style_a['align-self'] = self::calculate_align_self( $stored );
361+
$stored = $meta[ $key ];
362+
$style_a[ $rule['property'] ] = $stored;
363+
$style_a['align-self'] = isset( self::$align_self_map[ $stored ] ) ? self::$align_self_map[ $stored ] : 'center';
351364
continue;
352365
}
353366

@@ -525,21 +538,4 @@ public static function _add_menu_item_class( $classes, $item, $args ) { // phpcs
525538
$classes[] = 'menu-item';
526539
return $classes;
527540
}
528-
529-
/**
530-
* Calculate align-self value.
531-
*
532-
* @param string $value vertical-align value.
533-
* @return string
534-
*/
535-
private static function calculate_align_self( $value ) {
536-
$align_self_map = array(
537-
'top' => 'flex-start',
538-
'middle' => 'center',
539-
'bottom' => 'flex-end',
540-
'baseline' => 'baseline',
541-
);
542-
543-
return isset( $align_self_map[ $value ] ) ? $align_self_map[ $value ] : 'center';
544-
}
545541
}

0 commit comments

Comments
 (0)