question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Provide `ref` function to access the menu?

See original GitHub issue

Context: I would like to blur the menu when a selection is made, because the design for the focused state of our menu looks very “active”.

Is it possible to provide a ref function to access the menu’s focusable DOM element? I’m not sure if this would be tricky given the implementation of the library or not. Ideally I would be able to just call .blur() (or .focus(), etc.) on the menu whenever I’d like using a Ref.

Right now, I am doing this by:

import * as M from 'react-aria-menubutton'

...

    <M.Wrapper
        {...wrapperProps}
        onSelection={(selected: KeyType) => {
          onSelection(selected)

          // Blur the menu after selecting. we don't have a way to
          // get a ref for the menu, so this will have to do
          if (blurOnSelection) {
            // @ts-ignore
            document.activeElement &&
            // @ts-ignore
            document.activeElement.blur &&
            // @ts-ignore
            typeof document.activeElement.blur  === 'function' &&
            // @ts-ignore
            document.activeElement.blur()
          }
        }}
    >

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
vutrancommented, May 21, 2019

Context: I would like to blur the menu when a selection is made, because the design for the focused state of our menu looks very “active”.

This seems like it can be addressed by separating the active and focused state in the design instead of exposing the ref escape hatch. Additionally, the examples provided on w3 all keep the focus state on selection.

0reactions
ekilahcommented, May 21, 2019

It’s possible it’s not ARIA-favorable behavior to unfocus the menu on selection, but I think generally speaking it would be valuable to expose a ref from this library for focus state management.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to use custom functional components within Material-UI ...
In order to leverage the first child as the content anchor, Menu adds a ref to it (using cloneElement). In order to not...
Read more >
Menu Component "Function components cannot be given refs"
Attempts to access this ref will fail. Did you mean to use React.forwardRef()?. Check the render method of ForwardRef(Menu) .
Read more >
ref - dbt Developer Hub
The {{ ref }} function returns a Relation object that has the same table , schema , and name attributes at the {{...
Read more >
Everything You Need to Know About Refs in React
Short for “reference”, refs are a way to access underlying DOM elements in a React component. There are many reasons why you would...
Read more >
How to use React's forwardRef function - Felix Gerschau
forwardRef is a helper function from React that allows us to forward a component's ref to another one. This tutorial will teach what...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found