GithubHelp home page GithubHelp logo

Comments (3)

lukewarlow avatar lukewarlow commented on September 28, 2024

This is something that's come up for something before. We currently don't expose the type of interest (hover, focus, long press). Maybe we should do that so you could at least with a bit of JS decide whether to prevent default the event. But JS might not be the ideal here.

Pointer events while designed to be input agnostic do expose the type of input. So maybe this follows in the same theme?

from open-ui.

keithamus avatar keithamus commented on September 28, 2024

Interest invokers very specifically abstract away focus/hover to unify cross HID behaviours. I think if you want "interest invokers but just focus" then using the focus event is probably what you want. I'm not convinced we should extend interest invokers to facilitate exclusion or different semantics for a particular HID.

To more directly talk about your pattern though, a carousel is kind of a spicy tabpanel; it has a list of buttons that can be immediately activated and they will bring the matching panel to the front. They should also activate on click though. You could map the focus to a click, then use invokers to activate a custom element to switch the tab-panel. Given that, you might be better implementing a Carousel as tabpanels, and focusgroup might be a better fit for the tablist. In lieu of an actual tablist built-in, here's what I'd do:

<my-carousel id=carousel">
  <div role=tablist focusgroup slot=tablist>
    <button role=tab value=1 tabindex=-1 onfocus="this.onclick()" invoketarget="carousel">1</button>
    <button role=tab value=2 tabindex=-1 onfocus="this.onclick()" invoketarget="carousel">2</button>
    <button role=tab value=3 tabindex=-1 onfocus="this.onclick()" invoketarget="carousel">3</button>
  </div>
  <div role=tabpanel>1</div>
  <div role=tabpanel>2</div>
  <div role=tabpanel>3</div>
</my-carousel>
<script>
  customElements.define('my-carousel', class extends HTMLElement {
    connectedCallback() { this.addEventListener('invoke', this) }
    handleEvent(event) {
      const idx = event.target.closest('[role=tab]')?.value
      if (value) this.switchTo(idx)
    }
    switchTo(idx) {
      let i = 0;
      for(const panel of this.querySelectorAll('[role=tabpanel]')) {
        i += 1;
        panel.hidden = i != idx
      }
    }
  });
</script>

from open-ui.

flackr avatar flackr commented on September 28, 2024

Yes, totally agree that clicking should invoke the action as well, and that mapping focus to the invoke action is a way to solve this. I'd like to have a way to do this declaratively, otherwise it doesn't really explain the thing that the pseudo-element scroll markers create. I think this could well be some attribute value for focusgroup which implies invoking on focus.

E.g.

<my-carousel id=carousel">
  <div role=tablist focusgroup="invoke" slot=tablist>
    <button role=tab value=1 tabindex=-1 invoketarget="tab1" invokeaction="scrollTo">1</button>
    <button role=tab value=2 tabindex=-1 invoketarget="tab2" invokeaction="scrollTo">2</button>
    <button role=tab value=3 tabindex=-1 invoketarget="tab3" invokeaction="scrollTo">3</button>
  </div>
  <div role=tabpanel id=tab1>1</div>
  <div role=tabpanel id=tab2>2</div>
  <div role=tabpanel id=tab3>3</div>
</my-carousel>

As an example of the scrolling interaction you can see the demo at https://flackr.github.io/carousel/examples/carousel/image/ . The advantage of using scrolling is that it automatically supports swiping to advance.

As described in #1031 this alone wouldn't explain how the active button also needs to be updated on scroll.

from open-ui.

Related Issues (20)

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.