# spatial-navigation-ts

> A javascript-based implementation of Spatial Navigation with Typescript definitions.

Latest version **1.0.8** (published 2022-02-12) · MPL 2.0 license · 0 weekly downloads

## Install

```sh
npm install spatial-navigation-ts
pnpm add spatial-navigation-ts
yarn add spatial-navigation-ts
bun add spatial-navigation-ts
```

## Health

**Score 30/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities.

Warnings: low downloads; no esm support.

Negative: abandoned.

## Facts

| | |
|---|---|
| Version | 1.0.8 |
| Published | 2022-02-12 |
| First published | 2022-02-08 |
| Weekly downloads | 0 |
| License | MPL 2.0 |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 38.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 3 |
| Maintainers | valeragin |

## Links

- npm: https://www.npmjs.com/package/spatial-navigation-ts
- Repository: https://github.com/ValeraGin/spatial-navigation-ts
- Issues: https://github.com/ValeraGin/spatial-navigation-ts/issues
- npm.io page: https://npm.io/package/spatial-navigation-ts

## Recent versions

- 1.0.8 (latest) — 2022-02-12
- 1.0.7 — 2022-02-12
- 1.0.6 — 2022-02-08
- 1.0.4 — 2022-02-08
- 1.0.3 — 2022-02-08
- 1.0.2 — 2022-02-08
- 1.0.1 — 2022-02-08
- 1.0.0 — 2022-02-08

## README

# spatial-navigation-ts

A copy of the original library, without any modification ([JavaScript SpatialNavigation](https://github.com/luke-chang/js-spatial-navigation)), and typescript types.

This library works great in JS, Angular or pure typescript projects.

### Install
```bash
npm i spatial-navigation-ts
```

### Basic usage Angular
styles.scss
```scss
/* Add style to the focused elements */
:focus {
  outline: 2px solid red;
}
```

app.component.html
```html
<a id="test_1" href="#">Link 1</a>
<a href="#">Link 2</a>
<div class="focusable">Div 1</div>
<div class="focusable">Div 2</div>
```

app.component.ts
```typescript
import { Component, OnInit } from '@angular/core';
import SpatialNavigation from "spatial-navigation-ts";

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.scss']
})
export class AppComponent implements OnInit {

  ngOnInit(): void {
    this.initNavigation();
  }

  initNavigation() {
    SpatialNavigation.init();

    // Define navigable elements (anchors and elements with "focusable" class).
    SpatialNavigation.add({
      selector: 'a, .focusable'
    });

    // Make the *currently existing* navigable elements focusable.
    SpatialNavigation.makeFocusable();

    // Focus the first navigable element.
    SpatialNavigation.focus();
  }

}
```

### Basic usage JS

```html
<head>
  <script src="./node_modules/spatial-navigation-ts/spatial_navigation.js"></script>
  <script>
    window.addEventListener('load', function() {
      // Initialize
      SpatialNavigation.init();

      // Define navigable elements (anchors and elements with "focusable" class).
      SpatialNavigation.add({
        selector: 'a, .focusable'
      });

      // Make the *currently existing* navigable elements focusable.
      SpatialNavigation.makeFocusable();

      // Focus the first navigable element.
      SpatialNavigation.focus();
    });
  </script>
  <style>
    /* Add style to the focused elements */
    :focus {
      outline: 2px solid red;
    }
  </style>
</head>
<body>
  <a href="#">Link 1</a>
  <a href="#">Link 2</a>
  <div class="focusable">Div 1</div>
  <div class="focusable">Div 2</div>
</body>
```

### More Demonstrations

+ [Demonstrations](https://luke-chang.github.io/js-spatial-navigation/demo/)

---
_Source: https://npm.io/package/spatial-navigation-ts · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
