New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@mturco/menu-button

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@mturco/menu-button - npm Package Compare versions

Comparing version 0.1.7 to 0.1.8

2

package.json
{
"name": "@mturco/menu-button",
"version": "0.1.7",
"version": "0.1.8",
"description": "Accessible React button dropdown menu.",

@@ -5,0 +5,0 @@ "author": "Ryan Florence <@ryanflorence>",

@@ -90,49 +90,51 @@ import React from "react";

////////////////////////////////////////////////////////////////////////
let MenuButton = React.forwardRef(({ onClick, onKeyDown, ...props }, ref) => (
<Consumer>
{({ refs, state, setState }) => (
<Rect
observe={state.isOpen}
onChange={buttonRect => setState({ buttonRect })}
>
{({ ref: rectRef }) => (
<button
id={state.buttonId}
aria-haspopup="menu"
aria-expanded={state.isOpen}
data-reach-menu-button
type="button"
ref={node => {
rectRef(node);
ref && ref(node);
refs.button = node;
}}
onMouseDown={event => {
if (state.isOpen) {
setState({ closingWithClick: true });
}
}}
onClick={wrapEvent(onClick, event => {
if (state.isOpen) {
setState(close);
} else {
setState(openAtFirstItem);
}
})}
onKeyDown={wrapEvent(onKeyDown, event => {
if (event.key === "ArrowDown") {
event.preventDefault(); // prevent scroll
setState(openAtFirstItem);
} else if (event.key === "ArrowUp") {
event.preventDefault(); // prevent scroll
setState(openAtFirstItem);
}
})}
{...props}
/>
)}
</Rect>
)}
</Consumer>
));
let MenuButton = React.forwardRef(
({ onClick, onKeyDown, component: Comp = "button", ...props }, ref) => (
<Consumer>
{({ refs, state, setState }) => (
<Rect
observe={state.isOpen}
onChange={buttonRect => setState({ buttonRect })}
>
{({ ref: rectRef }) => (
<Comp
id={state.buttonId}
aria-haspopup="menu"
aria-expanded={state.isOpen}
data-reach-menu-button
type="button"
ref={node => {
rectRef(node);
ref && ref(node);
refs.button = node;
}}
onMouseDown={event => {
if (state.isOpen) {
setState({ closingWithClick: true });
}
}}
onClick={wrapEvent(onClick, event => {
if (state.isOpen) {
setState(close);
} else {
setState(openAtFirstItem);
}
})}
onKeyDown={wrapEvent(onKeyDown, event => {
if (event.key === "ArrowDown") {
event.preventDefault(); // prevent scroll
setState(openAtFirstItem);
} else if (event.key === "ArrowUp") {
event.preventDefault(); // prevent scroll
setState(openAtFirstItem);
}
})}
{...props}
/>
)}
</Rect>
)}
</Consumer>
)
);

@@ -142,2 +144,3 @@ MenuButton.propTypes = {

onKeyDown: func,
component: oneOfType([string, node]),
children: node

@@ -144,0 +147,0 @@ };

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc