mediawiki-skins-Vector/resources/skins.vector.styles/components/StickyHeader.less
Nicholas Ray 1209b388e9 Add scroll padding to the root element when the sticky header is enabled
When the sticky header is visible, it has a global impact on the
scrolling UX. For example, it can undesirably overlap elements when the
user clicks on a jump link and when the user tabs through elements in
reverse order. Therefore, we need to add scroll padding to the root
element when the sticky header is enabled (when the feature flag is on
and at higher resolutions)

Known limitations:

* Scroll padding is supported by all the latest modern browsers except
for Safari [1]. This was considered an acceptable tradeoff with the
caveat that this decision may be revisited in the future as we learn
more about user interaction with the sticky header.

[1] https://caniuse.com/mdn-css_properties_scroll-padding-top

Bug: T290518
Change-Id: Ie5eb01d7eafd18ce740be620dfb5c8849386af6e
2021-09-29 14:25:26 -06:00

147 lines
3.9 KiB
Plaintext

@import '../../common/variables.less';
@import 'mediawiki.mixins.less';
// Set an explicit height. This is needed for scroll padding and for other
// sticky elements on the page. Setting the height in relative units enables
// the header's height to adapt to the browser's font size setting.
@height-sticky-header: unit( 60px / @font-size-browser, em );
.vector-sticky-header {
width: 100%;
height: @height-sticky-header;
position: fixed;
top: 0;
left: 0;
right: 0;
z-index: @z-index-header;
transform: translateY( -100% );
transition: transform 250ms linear;
display: flex;
align-items: center;
max-width: @max-width-page-container + @padding-horizontal-page-container + @padding-horizontal-page-container;
margin: 0 auto;
background: @background-color-base;
background-color: #fffffff7;
border-bottom: 1px solid @colorGray14;
// FIXME: Should this adapt to different thresholds? Ask Alex!
padding: 6px 8px 6px 10px;
justify-content: space-between;
box-sizing: border-box;
// If the user has expressed their preference for reduced motion, then disable animation for the sticky header.
@media ( prefers-reduced-motion: reduce ) {
transition: none;
}
@media ( min-width: @width-breakpoint-desktop ) {
padding: 6px 25px;
}
// T289714 Hide the sticky header at lower resolutions.
@media ( max-width: @width-breakpoint-tablet ) {
display: none;
}
// Hide any open menus/search results unless sticky header is visible
&:not( .vector-sticky-header-visible ) > div {
display: none;
}
&-visible {
transform: translateY( 0% );
}
//
// Layout
//
&-start {
display: flex;
align-items: center;
flex-grow: 1;
}
&-end {
display: flex;
align-items: center;
}
//
// Components
//
&-icons,
&-context-bar {
display: flex;
align-items: center;
white-space: nowrap;
margin: 0 15px;
padding-left: 30px;
}
&-context-bar {
border-left: 1px solid #c8c8c8;
}
&-context-bar-primary {
position: relative;
max-width: 500px;
overflow: hidden;
// T289814 Fade out page titles longer than 500px.
/* Stylelint rule broken for vendor prefixes: https://github.com/stylelint/stylelint/issues/1939 */
/* stylelint-disable function-linear-gradient-no-nonstandard-direction */
&:after {
content: '';
position: absolute;
left: 480px;
width: 100%;
height: 100%;
background-color: transparent;
background-image: -webkit-linear-gradient( to right, rgba( 255, 255, 255, 0 ), rgba( 255, 255, 255, 1 ) 20px );
background-image: linear-gradient( to right, rgba( 255, 255, 255, 0 ), rgba( 255, 255, 255, 1 ) 20px );
}
}
.vector-search-box {
// Hide the search box until the user toggles it.
display: none;
}
&.vector-header-search-toggled {
.vector-sticky-header-search-toggle,
.vector-sticky-header-context-bar {
display: none;
}
.vector-search-box {
display: block;
flex-basis: unit( 500px / @font-size-browser / @font-size-base, em );
}
// Increase the start margin of the search box to account for the input
// expanding on focus.
.vector-search-box-show-thumbnail {
margin-left: @size-search-expand;
}
}
}
.client-nojs .vector-sticky-header {
display: none;
}
// T290518: When the sticky header is enabled (feature flag is on, js is
// enabled, and viewport is at higher resolutions), add scroll padding to the
// root element. This is needed so that the sticky header does not overlap the
// top of an element when the URI has a hash fragment (e.g. when the user clicks
// a jump link) and when the user tabs through elements in reverse order.
//
// Please note that this class must be independent of the
// .vector-sticky-header-visible class 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).
@media ( min-width: @width-breakpoint-tablet ) {
.client-js.vector-sticky-header-enabled {
scroll-padding-top: @height-sticky-header;
}
}