3.0.9 • Published 3 months ago

@zendeskgarden/container-selection v3.0.9

Weekly downloads
14,528
License
Apache-2.0
Repository
github
Last release
3 months ago

@zendeskgarden/container-selection npm version

This package includes containers relating to selection in the Garden Design System.

Installation

npm install @zendeskgarden/container-selection

Usage

Check out storybook for live examples.

useSelection

The useSelection hook which manages an items focus state including keyboard controls, aria attributes and RTL support. It uses the roving tab index strategy.

import { useSelection } from '@zendeskgarden/container-selection';

const values = ['Value 1', 'Value 2', 'Value 3'];

const Selection = ({ direction }) => {
  const { focusedValue, selectedValue, getGroupProps, getElementProps } = useSelection({
    values,
    direction
  });

  return (
    <ul {...getGroupProps()}>
      {values.map(value => {
        const isSelected = selectedValue === value;
        const isFocused = focusedValue === value;

        return (
          <li {...getElementProps({ key: value, value })}>
            {value}
            {isSelected && <div>[Selected]</div>}
            {isFocused && <div>(Focused)</div>}
          </li>
        );
      })}
    </ul>
  );
};

SelectionContainer

import { SelectionContainer } from '@zendeskgarden/container-selection';

const values = ['Value 1', 'Value 2', 'Value 3'];

<SelectionContainer direction="vertical" values={values}>
  {({ selectedValue, focusedValue, getGroupProps, getElementProps }) => (
    <ul {...getGroupProps()}>
      {values.map(value => {
        const isSelected = value === selectedValue;
        const isFocused = value === focusedValue;

        return (
          <li {...getElementProps({ key: value, value })}>
            {item}
            {isSelected && <span> - Selected</span>}
            {isFocused && <span> - Focused</span>}
          </li>
        );
      })}
    </ul>
  )}
</SelectionContainer>;
3.0.8

3 months ago

3.0.9

3 months ago

3.0.7

3 months ago

3.0.4

8 months ago

3.0.3

8 months ago

3.0.2

9 months ago

3.0.1

10 months ago

3.0.6

7 months ago

3.0.5

7 months ago

3.0.0

10 months ago

2.0.6

11 months ago

2.0.5

1 year ago

2.0.4

1 year ago

2.0.2

1 year ago

1.3.17

2 years ago

1.3.18

2 years ago

2.0.1

2 years ago

2.0.0

2 years ago

1.3.14

2 years ago

1.3.15

2 years ago

1.3.16

2 years ago

1.3.13

3 years ago

1.3.12

3 years ago

1.3.10

3 years ago

1.3.9

3 years ago

1.3.8

3 years ago

1.3.7

4 years ago

1.3.6

4 years ago

1.3.5

4 years ago

1.3.4

4 years ago

1.3.3

4 years ago

1.3.2

4 years ago

1.3.1

4 years ago

1.3.0

4 years ago

1.2.8

4 years ago

1.2.7

4 years ago

1.2.6

4 years ago

1.2.5

4 years ago

1.2.4

4 years ago

1.2.3

5 years ago

1.2.2

5 years ago

1.2.1

5 years ago

1.2.0

5 years ago

1.1.6

5 years ago

1.1.5

5 years ago

1.1.4

5 years ago

1.1.3

5 years ago

1.1.2

5 years ago

1.1.1

5 years ago

1.1.0

5 years ago

1.0.2

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago

0.3.0

5 years ago

0.2.3

5 years ago

0.2.2

5 years ago

0.2.1

5 years ago

0.2.0

5 years ago

0.1.2

5 years ago

0.1.1

5 years ago

0.1.0

5 years ago