Move code for adding sticky header class to SkinVector22.php

Per the comment at the top of the file, much more of this code
needs to be moved to SkinVector22.php, but this is causing a specific
regression, so can be moved now.

Bug: T312782
Change-Id: Ief7581782f1e4eefc7474cceb81830783dff99a8
This commit is contained in:
Ed Sanders 2022-07-11 16:10:26 +01:00
parent 88b7d9534a
commit e2d70c383e
2 changed files with 25 additions and 25 deletions

View File

@ -117,7 +117,6 @@ abstract class SkinVector extends SkinMustache {
];
private const SEARCH_SHOW_THUMBNAIL_CLASS = 'vector-search-box-show-thumbnail';
private const SEARCH_AUTO_EXPAND_WIDTH_CLASS = 'vector-search-box-auto-expand-width';
private const STICKY_HEADER_ENABLED_CLASS = 'vector-sticky-header-enabled';
private const CLASS_QUIET_BUTTON = 'mw-ui-button mw-ui-quiet';
private const CLASS_PROGRESSIVE = 'mw-ui-progressive';
private const CLASS_ICON_BUTTON = 'mw-ui-icon mw-ui-icon-element';
@ -370,30 +369,6 @@ abstract class SkinVector extends SkinMustache {
Hooks::onSkinTemplateNavigation( $skin, $content_navigation );
}
/**
* @inheritDoc
*/
public function getHtmlElementAttributes() {
$original = parent::getHtmlElementAttributes();
if ( VectorServices::getFeatureManager()->isFeatureEnabled( Constants::FEATURE_STICKY_HEADER ) ) {
// T290518: Add scroll padding to root element when the sticky header is
// enabled. This class needs to be server rendered instead of added from
// JS in order to correctly handle situations where the sticky header
// isn't visible yet but we still need scroll padding applied (e.g. when
// the user navigates to a page with a hash fragment in the URI). For this
// reason, we can't rely on the `vector-sticky-header-visible` class as it
// is added too late.
//
// Please note that this class applies scroll padding which does not work
// when applied to the body tag in Chrome, Safari, and Firefox (and
// possibly others). It must instead be applied to the html tag.
$original['class'] = implode( ' ', [ $original['class'] ?? '', self::STICKY_HEADER_ENABLED_CLASS ] );
}
return $original;
}
/**
* Generate data needed to generate the sticky header.
* @param array $searchBoxData

View File

@ -11,6 +11,7 @@ use MediaWiki\MediaWikiServices;
*/
class SkinVector22 extends SkinVector {
private const TOC_AB_TEST_NAME = 'skin-vector-toc-experiment';
private const STICKY_HEADER_ENABLED_CLASS = 'vector-sticky-header-enabled';
/**
* Updates the constructor to conditionally disable table of contents in article
@ -137,6 +138,30 @@ class SkinVector22 extends SkinVector {
return $data;
}
/**
* @inheritDoc
*/
public function getHtmlElementAttributes() {
$original = parent::getHtmlElementAttributes();
if ( VectorServices::getFeatureManager()->isFeatureEnabled( Constants::FEATURE_STICKY_HEADER ) ) {
// T290518: Add scroll padding to root element when the sticky header is
// enabled. This class needs to be server rendered instead of added from
// JS in order to correctly handle situations where the sticky header
// isn't visible yet but we still need scroll padding applied (e.g. when
// the user navigates to a page with a hash fragment in the URI). For this
// reason, we can't rely on the `vector-sticky-header-visible` class as it
// is added too late.
//
// Please note that this class applies scroll padding which does not work
// when applied to the body tag in Chrome, Safari, and Firefox (and
// possibly others). It must instead be applied to the html tag.
$original['class'] = implode( ' ', [ $original['class'] ?? '', self::STICKY_HEADER_ENABLED_CLASS ] );
}
return $original;
}
/**
* @return array
*/