1.0.0-alpha.1 • Published 2 years ago

@bbc/psammead-content-anchor v1.0.0-alpha.1

Weekly downloads
624
License
Apache-2.0
Repository
github
Last release
2 years ago

⛔️ This is an alpha component ⛔️

This component is currently tagged as alpha and is not suitable for production use. Following the passing of an accessibility review this component will be marked as ready for production and the alpha tag removed.

psammead-content-anchor - Known Vulnerabilities Dependency Status peerDependencies Status Storybook GitHub license npm version PRs Welcome

Description

ContentAnchor is a component to mitigate the jarring user experience of the page moving while the user is in the middle of consuming the content.

Today, users of the web are often distracted by content moving around due to changes that occur outside the viewport. Examples include script inserting an iframe containing an ad, or non-sized images loading on a slow network. - CSS Working Group

Such content can be wrapped with ContentAnchor to prevent the page from jumping around.

⚠️ Side-effects: This component enables scroll-anchoring by adding overflow-anchor: auto style to the body tag. We recommend you don't override this style and that you also don't explicitly set overflow-anchor: none on any parent elements of ContentAnchor. If you do then the user may experience content shifting.

How it works

ContentAnchor will never resize when in view even if the child content resizes. ContentAnchor content is allowed to resize when it is outside of the viewport. If the ContentAnchor component is above the scrollable region of the viewport and scroll height of the page changes then the Y scroll position is adjusted to prevent a vertical scroll jump that would disrupt the user's reading experience. This technique is called scroll anchoring and can be achieved by setting overflow-anchor: auto on a scrollable container such as the body element. It is enabled in Chrome 56 and Firefox 66 https://caniuse.com/#feat=css-overflow-anchor as an opt-out for developers and is implemented in ContentAnchor using javascript for browsers that do not have support for overflow-anchor.

Installation

npm install @bbc/psammead-content-anchor --save

Props

ArgumentTypeRequiredDefaultExample
childrennodetrue
initialHeightString/Numberfalse'auto'400
initialWidthString/Numberfalse'auto'400

Note - children does not support passing in a React Fragment wrapping several children. Should be e.g. a div.

Usage

import ContentAnchor from  '@bbc/psammead-content-anchor';

<ContentAnchor
  initialHeight={400}
  initialWidth={400}
>
  <Advertisement>
</ContentAnchor>

When to use this component

When you need to use e.g. 3rd party components and want to prevent unexpected visible content jumps. You can use this wrap content such as Visual Journalism content, IDT (data) components and adverts.

When not to use this component

When you are absolutely sure that the child content will never resize.

Accessibility notes

Roadmap

Contributing

Psammead is completely open source. We are grateful for any contributions, whether they be new components, bug fixes or general improvements. Please see our primary contributing guide which can be found at the root of the Psammead repository.

Code of Conduct

We welcome feedback and help on this work. By participating in this project, you agree to abide by the code of conduct. Please take a moment to read it.

License

Psammead is Apache 2.0 licensed.

2.0.0-alpha.31

2 years ago

2.0.0-alpha.30

2 years ago

2.0.0-alpha.29

3 years ago

2.0.0-alpha.28

3 years ago

2.0.0-alpha.27

3 years ago

2.0.0-alpha.26

3 years ago

2.0.0-alpha.25

3 years ago

2.0.0-alpha.24

3 years ago

2.0.0-alpha.22

3 years ago

2.0.0-alpha.23

3 years ago

2.0.0-alpha.21

3 years ago

2.0.0-alpha.20

3 years ago

2.0.0-alpha.19

3 years ago

2.0.0-alpha.18

3 years ago

2.0.0-alpha.17

3 years ago

2.0.0-alpha.16

3 years ago

2.0.0-alpha.15

3 years ago

2.0.0-alpha.14

3 years ago

2.0.0-alpha.13

3 years ago

2.0.0-alpha.12

3 years ago

2.0.0-alpha.11

3 years ago

2.0.0-alpha.10

3 years ago

2.0.0-alpha.8

3 years ago

2.0.0-alpha.9

3 years ago

2.0.0-alpha.7

3 years ago

2.0.0-alpha.6

3 years ago

2.0.0-alpha.5

3 years ago

2.0.0-alpha.4

3 years ago

2.0.0-alpha.3

4 years ago

2.0.0-alpha.2

4 years ago

2.0.0-alpha.1

4 years ago

2.0.0-alpha.0

4 years ago

1.0.0-alpha.15

4 years ago

1.0.0-alpha.14

4 years ago

1.0.0-alpha.13

4 years ago

1.0.0-alpha.12

4 years ago

1.0.0-alpha.10

4 years ago

1.0.0-alpha.11

4 years ago

1.0.0-alpha.9

4 years ago

1.0.0-alpha.8

4 years ago

1.0.0-alpha.7

4 years ago

1.0.0-alpha.6

4 years ago

1.0.0-alpha.5

4 years ago

1.0.0-alpha.4

4 years ago

1.0.0-alpha.3

4 years ago

1.0.0-alpha.2

4 years ago

1.0.0-alpha.1

4 years ago