Coder Social home page Coder Social logo

vaadin-component-factory / vcf-toggle-button Goto Github PK

View Code? Open in Web Editor NEW
1.0 8.0 2.0 30 KB

Vaadin Component Factory Toggle Button.

Home Page: https://vcf-toggle-button.netlify.com/

License: Apache License 2.0

HTML 17.46% JavaScript 82.54%
vaadin polymer3 webcomponent toggle-button toggle toggle-switch switch

vcf-toggle-button's Introduction

<vcf-toggle-button>

Demo

https://vcf-toggle-button.netlify.com/

Installation

Install vcf-toggle-button:

npm i @vaadin-component-factory/vcf-toggle-button --save

Usage

Once installed, import it in your application:

import '@vaadin-component-factory/vcf-toggle-button';

And use it:

<vcf-toggle-button></vcf-toggle-button>

Attributes

  • label: Provide a label for the toggle button.
  • checked: Changes the state of toggle button to "on".
  • disabled: Disables the toggle button.

Event

  • change: Fires whenever the state of the toggle button is changed:
document.querySelector('vcf-toggle-button').addEventListener('change', e => {
  console.log(e.detail.checked);
});

Running demo

  1. Fork the vcf-toggle-button repository and clone it locally.

  2. Make sure you have npm installed.

  3. When in the vcf-toggle-button directory, run npm install to install dependencies.

  4. Run npm start to open the demo.

Contributing

To contribute to the component, please read the guideline first.

License

Apache License 2.0

vcf-toggle-button's People

Contributors

paodb avatar sohrabtaee avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

vcf-toggle-button's Issues

Toggle slider looks off with V23

The slider looks a few pixels too big and is not centered within the slit:
on off

Attached project with a single view containing the component.
basic.zip.

Versions:

  • Vaadin 23.0.3
  • vcf-toggle-button: 1.0.3

Accessibility for screen readers

This component is (IMO) commonly used. We're using it (Vaadin 22) and it's great. After all, toggle is one of the important elements of the UI interface.
But it turns out (notifications from our blind users) that it is completely invisible to screen readers (eg. NVDA), and it is impossible to tick its value by the blind. There is of course a way to select this field via keyboard but screen readers say nothing about this field because the internal checkbox field takes this focus and there is no aria-label, no title on it. So the user doesn't know when he is about to use the keyboard to tick the value.
Setting aria-label on the root tag is not enough because the root tag takes no focus. We can set tabindex to it, but then user thinks he can set the value via keyboard, but no, because focus is not on the checkbox.
We managed to somehow improve it, i.e. through javascript set the keyevent to the space key when focus is on the root tag and set the checkbox value on / off. And it works. But it is a hack way in javascript to take shadow element (this.shadowRoot.querySelector('vaadin-checkbox')).

I think it would be very nice to add this component to the list of changes regarding accessibility, which were started with Vaadin 22 :)
https://vaadin.com/blog/upcoming-accessibility-improvements

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.