How to install the accessibility widget as an NPM package
The following documentation shows how to install, initialize, and use the accessibility widget in TypeScript/JavaScript projects using the @dockcodes/accessibility-widget package..
1. Installing the package
Using NPM:
or Yarn:
2. Basic use
3. Widget initialization
To properly run the widget, call the init() method with a valid API token: await accessibility.init("YOUR_TOKEN"); 🔑 You can generate a token for free here: wcag.dock.codes/my-account/tokens/ (opens in a new tab)
4. Managing widget functions
The library provides a rich set of methods for controlling accessibility features.
Examples of the most commonly used methods:
5. Full list of available methods
| Method | Description |
|---|---|
| toggleContrast() | Enable/Disable contrast |
| setContrast(enabled: boolean) | Sets the contrast |
| toggleInvertColors() | Inverts colors |
| setInvertColors(enabled: boolean) | Sets color inversion |
| toggleUnderline() | Link underlines |
| setUnderline(enabled: boolean) | Sets link underlines |
| setFontSize(level: number) | Set font size 1-5 |
| increaseFontSize() | Increases font size |
| decreaseFontSize() | Reduces font size |
| increaseLetterSpacing() | Increase spacing |
| setLetterSpacing(level: number) | Sets spacing 1-5 |
| increaseLineHeight() | Increases line height |
| setLineHeight(level: number) | Sets the height of lines 1-5 |
| increaseSaturation() | Increases saturation |
| setSaturation(level: number) | Sets the saturation 1-3 |
| toggleTextToSpeech() | TTS – reading content |
| setTextToSpeech(enabled: boolean) | Enables/disables TTS |
| toggleCursorEnlarge() | Enlarged cursor |
| setCursorEnlarge(enabled: boolean) | Enables the enlarged cursor |
| toggleHideMedia() | Hide media |
| setHideMedia(enabled: boolean) | Enables/disables media hiding |
| toggleDisableAnimations() | Disables animations |
| setDisableAnimations(enabled: boolean) | Enables/disables animations |
| toggleReadingGuide() | Reading guide line |
| setReadingGuide(enabled: boolean) | Enables/disables the guide |
| toggleDyslexicFont() | Font for dyslexics |
| setDyslexicFont(enabled: boolean) | Enables font for dyslexics |
| toggleProfileBlind() | Profile for the completely blind |
| setProfileBlind(enabled: boolean) | Sets the blind profile |
| toggleProfileLowVision() | Low Vision Profile |
| toggleProfileEpileptic() | Epileptic-safe profile |
| resetAll() | Reset all options |
6. Event Handlers
Widget udostępnia zdarzenia, które możesz wykorzystać np. do analityki lub integracji z aplikacją.
List of available events:
7. Integration with Google Tag Manager
8. Resetting settings
You can restore the widget settings to their default values at any time: accessibility.resetAll();
9. Sources and bug reporting
👉 If you encounter an issue or would like to submit an enhancement request, please visit: GitHub (opens in a new tab)
Related posts
- How to install the accessibility widget in Joomla
- Accessibility widget script
- How to install the accessibility widget in MODX
- How to install the accessibility widget in Prestashop
- How to install the accessibility widget in WordPress
Still looking for answers?
Ask our experts using online chat