---
title: Sticky
---

import LibraryInfo from '@theme/LibraryInfo'
import { Feedback, FigmaEmbed, PropsTable } from '../../src/components'
import { Sticky } from '@telus-uds/components-community'
import { Sticky as WebDocs } from 'docs/@telus-uds/components-community'
import AvailableOnWebOnly from '../../partials/_platform-considerations-web-only.mdx'
import NoStylisticVariants from '../../partials/_variants-none.mdx'

# Sticky

<LibraryInfo
  packageType="Web Component"
  packageName="components-community.sticky"
  compatibility={['React 18']}
  figmaLink=""
/>

```jsx live
<div style={{ height: '300px', overflow: 'scroll', position: 'relative' }}>
  <div style={{ height: '200vh' }}>
    <Sticky variant="default" workWithViewport={false}>
      <FlexGrid>
        <FlexGridRow horizontalAlign="center">
          <FlexGridCol>
            <Box variant={{ background: 'brand' }} space={2}>
              <Typography block variant={{ size: 'h1', inverse: true }}>
                Sticky Content
              </Typography>
              <Spacer space={4} />
              <Typography align="center" variant={{ inverse: true }}>
                Lorem ipsum dolor sit amet, consectetur adipiscing elit.
              </Typography>
            </Box>
          </FlexGridCol>
        </FlexGridRow>
      </FlexGrid>
    </Sticky>
  </div>
</div>
```

## Introduction

```jsx
import { Sticky } from '@telus-uds/components-community.sticky'
```

The Sticky component is a reusable element that enables content to remain fixed in position within a scrollable container.

[Follow the appropriate instructions](importing-components) to add this component in to your app.

## Guidance

Sticky component is designed as a container component, this will allows you to make content sticky on the sceen. You can choose from three different variants to customize the behaviour of the Sticky component.

It has no margins or borders on the outside and it will fill it's parent container meaning it can also be placed inside other components without causing layout issues.

### Platform considerations

<AvailableOnWebOnly />

## Props

<PropsTable web={WebDocs} />

## Variants

### Alternate

- The component becomes sticky once it scrolls out of the view

```jsx live
<div style={{ height: '300px', overflow: 'scroll', position: 'relative' }}>
  <div style={{ height: '200vh' }}>
    <Sticky variant={'alternate'} workWithViewport={false}>
      <FlexGrid>
        <FlexGridRow horizontalAlign="center">
          <FlexGridCol>
            <Box variant={{ background: 'brand' }} space={2}>
              <Typography block variant={{ size: 'h1', inverse: true }}>
                Sticky Content
              </Typography>
              <Spacer space={4} />
              <Typography align="center" variant={{ inverse: true }}>
                Lorem ipsum dolor sit amet, consectetur adipiscing elit.
              </Typography>
            </Box>
          </FlexGridCol>
        </FlexGridRow>
      </FlexGrid>
    </Sticky>
  </div>
</div>
```

### Hidden

- The component is not visible at the start
- The component becomes sticky & visible once it scrolls out of the view

```jsx live
<div>
  <div style={{ height: '300px', overflow: 'scroll', position: 'relative' }}>
    <div style={{ height: '200vh' }}>
      <p>Scroll down...</p>
      <Sticky variant={'hidden'} workWithViewport={false}>
        <FlexGrid>
          <FlexGridRow horizontalAlign="center">
            <FlexGridCol>
              <Box variant={{ background: 'brand' }} space={2}>
                <Typography block variant={{ size: 'h1', inverse: true }}>
                  Sticky Content
                </Typography>
                <Spacer space={4} />
                <Typography align="center" variant={{ inverse: true }}>
                  Lorem ipsum dolor sit amet, consectetur adipiscing elit.
                </Typography>
              </Box>
            </FlexGridCol>
          </FlexGridRow>
        </FlexGrid>
      </Sticky>
    </div>
  </div>
  <p>To see the Sticky Bar</p>
</div>
```

### No shadow and position set to bottom

```jsx live
<div style={{ height: '300px', overflow: 'scroll' }}>
  <div
    style={{
      height: '200vh',
      position: 'relative',
      display: 'flex',
      flexDirection: 'column-reverse'
    }}
  >
    <Sticky variant="default" workWithViewport={false} shadow={false} position={'bottom'}>
      <FlexGrid>
        <FlexGridRow horizontalAlign="center">
          <FlexGridCol>
            <Box variant={{ background: 'featurePrimary' }} space={2}>
              <Typography block variant={{ size: 'h1', inverse: true }}>
                Sticky Content
              </Typography>
              <Spacer space={4} />
              <Typography align="center" variant={{ inverse: true }}>
                Lorem ipsum dolor sit amet, consectetur adipiscing elit.
              </Typography>
            </Box>
          </FlexGridCol>
        </FlexGridRow>
      </FlexGrid>
    </Sticky>
  </div>
</div>
```

## Feedback

<Feedback component="Sticky" />
