パッケージの詳細

@material/react-menu-surface

material-components6.5kMIT0.15.0

Material Components React Menu Surface

mdc web react, material components react, material design, menu surface

readme

React Menu Surface

A React version of an MDC Menu Surface.

Installation

npm install @material/react-menu-surface

Usage

Styles

with Sass:

import '@material/react-menu-surface/index.scss';

with CSS:

import '@material/react-menu-surface/dist/menu-surface.css';

Javascript Instantiation

Anchored to Element

React Menu Surface accepts one child element. Please see the below example if you need to anchor the menu surface to a specific element. In this case, we wrapper <button> and <MenuSurface> element within the anchor, and give the mdc-menu-surface--anchor class to the element. You can specify a corner for the menu surface to appear from, otherwise it defaults to top-left. For a list of different anchor corner values, please see the MDC Web Menu Surface constants.ts file.

NOTE: <MenuSurface> also has an onClose callback method prop, which is called when the menu closes. Use this as an opportunity to update your application's state.

import React from 'react';
import MenuSurface, {Corner} from '@material/react-menu-surface';
import Button from '@material/react-button';

class MyApp extends React.Component {
  state = {
    open: false,
    anchorElement: null,
  };

  setAnchorElement = (element) => {
    if (this.state.anchorElement) {
      return;
    }
    this.setState({anchorElement: element});
  }

  render() {
    return (
      <div
        className='mdc-menu-surface--anchor'
        ref={this.setAnchorElement}
      >
        <Button raised onClick={() => this.setState({open: true})}>Open Menu</Button>

        <MenuSurface
          open={this.state.open}
          anchorCorner={Corner.BOTTOM_LEFT}
          onClose={() => this.setState({open: false})}
          anchorElement={this.state.anchorElement}
        >
          <img
            style={{maxWidth: '20vw', maxHeight: '20vh'}}
            src='http://images.my.photo.url' />
        </MenuSurface>
      </div>
    );
  }
}

Anchored to Coordinates (right-click)

You may want to anchor your menu surface to x, y coordinates. One example being a right-click contextmenu. Instead of passing an anchorElement you need to pass coordinates.

import React from 'react';
import MenuSurface from '@material/react-menu-surface';

class MyApp extends React.Component {
  state = {
    open: false,
    coordinates: null,
  };

  componentDidMount() {
    this.rightClickCallback_ = (evt) => {
      this.setState({
        open: true,
        coordinates: {x: evt.clientX, y: evt.clientY},
      });
      evt.preventDefault();
    };

    window.addEventListener('contextmenu', this.rightClickCallback_);
  }

  componentWillUnmount() {
    window.removeEventListener('contextmenu', this.rightClickCallback_);
  }

  render() {
    return (
      <div className='my-app'>
        <h1>Menu Surface</h1>

        <MenuSurface
          open={this.state.open}
          onClose={() => this.setState({open: false, coordinates: null})}
          coordinates={this.state.coordinates}
        >
          <img
            style={{maxWidth: '20vw', maxHeight: '20vh'}}
            src='http://images.my.photo.url' />
        </MenuSurface>
      </div>
    );
  }
}

NOTE: The React menu surface component is always hoisted to the body. This is one place the component differs from MDC Web's version, which gives the option of hoisting/not hoisting. Always hoisting the menu surface to the body allows fixes a few issues, and simplifies the component API.

Props

Prop Name Type Description
className String Classes to be applied to the root element.
anchorCorner Corner Sets the corner that the menu surface will be anchored to. See MDC Web constants.js.
anchorElement Element Sets the anchor element used as an anchor for menu-surface positioning logic. Should contain class .mdc-menu-surface--anchor.
anchorMargin Object* Sets the distance from the anchor point that the menu surface should be shown.
coordinates {x: Number, y: Number} Sets the anchor coordinates when menu surface does not use anchorElement.
open Boolean Changing value will trigger open/close of the menu surface.
quickOpen Boolean Disables the open/close animation of the menu surface, which makes the open/close instant.
fixed Boolean Sets the menu surface to fixed positioning.
onClose Function Callback triggered after menu surface closes.
  • | AnchorMargin takes the form of {top: Number, bottom: Number , left: Number , right : Number}

Sass Mixins

Sass mixins may be available to customize various aspects of the components. Please refer to the MDC Web repository for more information on what mixins are available, and how to use them.

Advanced Sass Mixins

Usage with Icons

Please see our Best Practices doc when importing or using icon fonts.

更新履歴

0.15.0 (2019-07-22)

Bug Fixes

  • infrastructure: chips need unique key (#974) (58408c8)
  • infrastructure: add eslint ignore lines (#973) (7172019)
  • list: Only apply aria-orientation with role (#945) (beab319)
  • list: Remove selected & activated from prop spread (#977) (4f36078)
  • ripple: broken relative imports (#953) (aabe0c1)

Features

  • list: Implement getAttributeForElementIndex (#948) (00f2ef1)

BREAKING CHANGES

  • list: 'orientation` is now used instead of 'aria-orientation' to specify list orientation. This allows smarter aria defaults that can be overridden if needed.

0.14.1 (2019-07-02)

Bug Fixes

  • infrastructure: fix SSR support for webpack4 update (#956) (5d3a89d)

0.14.0 (2019-06-25)

Bug Fixes

  • master on travis.yml (#922) (407de75)
  • infrastructure: update docker command to run new image (#923) (10a68f6)
  • npm vulnerabilities (#903) (92a1840)
  • switch react to peerDependency for all packages (#940) (cc06add)
  • ripple: focus style alive when disabled (#943) (e222e94)
  • ripple: not activating when clicked after touch (#932) (b2f7855)
  • text-field: label isn't float when set value with setState (#934) (f829e12)

chore

Features

  • infrastructure: add typescript production typings test (#900) (1f7f872)
  • select: add 'form' attribute to NativeControl component (#907) (044117f)
  • tab: Allow to render Tab as an anchor node (#928) (5108e76)
  • text-field: add placeholder property (#930) (0818061)

BREAKING CHANGES

  • text-field: handleValueChange is removed from Input's props.
  • top-app-bar: Top App Bar render props removed

0.13.2 (2019-06-11)

Bug Fixes

  • list: update checkbox and radio deps (#919) (685b23b)

0.13.0 (2019-05-30)

Bug Fixes

  • chips: ClientRect/DOMRect is not IE11 compatible (#855) (88697da)
  • chips: error with undefined or null children (#883) (d733c29)
  • chips, text-field: add null check for foundation (#675) (#870) (40ca635)
  • select: className option is passed to select and overrides selectClassName (#872) (6e2aac1)
  • select: componentDidUpdate handles disabled prop change (#877) (db7f0ce)
  • select: edit * imports (#874) (33eb962)

Features

0.12.1 (2019-05-08)

Bug Fixes

  • fab: Made initRipple and unbounded props optional (#854) (baca67b)
  • infrastructure: fix postinstall (#842) (5077078)

Features

  • button: define CSS_CLASSES (#838) (cbf6cc5)
  • text-field: Sync inputComponent when component is updated (#848) (2b954fa )

0.12.0 (2019-05-01)

Bug Fixes

  • list make listitem props optional (#766) (ffd7776)
  • top-app-bar change scrollTop to offsetTop in getViewportScrollY ( (#832) (a207b0d)
  • Ensure all package.json files have a link to the repo (#807) (10f2614)
  • Remove MDCTextfield Constant External (#803) (2269920)

Features

BREAKING CHANGES

  • Text-field, select, list have API changes. Please see PR #830 for more details.

0.11.0 (2019-03-19)

Bug Fixes

  • chips: update classnames version to 2.2.6 (#702) (bfd2986)
  • dialog: should extend HTMLElement (#723) (af449f4)
  • infrastructure: remove duplicate tsconfig properties (#736) (582cca3)
  • menu-surface: Hoist menu-surface via a portal (#500,#628) (#693) (41d8750)
  • ripple: ClientRect => defaultrect object (#754) (b2f78e8)
  • ripple: Use mdc-dom.matches instead of getMatchesProperty() (#706) (74d07fd)
  • select: pass state.value to NativeControl as prop.value (#726) (09ad132)
  • classnames@2.2.5 --> classnames@2.2.6 & update imports (#709) (230337e)
  • make require props optional (#737) (f4e78e7)
  • select: prop value should be string only (#725) (619d12c)
  • snackbar: Add missing mdcw snackbar dependency (#714) (9e6fc92)
  • tab: Set initial tabIndex state to -1 (#690) (#691) (9034c98)
  • text-field: make props optional (#735) (93e8c15)

Features

0.10.0 (2019-02-19)

Bug Fixes

  • button: Support anchor and button HTML attributes (#679) (#680) (be8790e)
  • checkbox: enable name attribute (#678) (2c77ab5)
  • chips: ChipSet no longer overwrites handle[Interaction|Select|Re… (#651) (e0b0946)
  • chips: copy selectedChipIds before calling setState (#645) (37905d3)
  • chips: id shuold be required prop (#649) (afc16c8)
  • infrastructure: fix source mappings under dist directory (#682) (9f93ef3)
  • infrastructure: Upgrade resemblejs to v3 (#634) (53abeac)
  • infrastructure: Windows development (#662) (fbc4b26)
  • list: renders a list with children which is not DOM (#674) (e66a267)
  • ripple: Ripple triggers twice on mobile (#646) (6876e62)
  • tab: return ScrollContentWidth (#633) (c4a2a01)
  • text-field: Do not import constants from @material/textfield internals (#639) (3b3a0ab)
  • top-app-bar: clientHeight unit test (#668) (9c7330b)

Features

  • chips: implements missing adapter method notifyTrailingIconInteraction (#653) (c5e87a6)
  • fab: exited (#661) (a646a33)
  • infrastructure: Fix screenshot tests for external contributors and pull requests (#638) (3d421b1)
  • snackbar: new component (#620) (63e1fce)

BREAKING CHANGES

  • chips: renamed chip.props.removeIcon --> chips.props.trailingIcon

0.9.3 (2019-02-14)

Bug Fixes

0.9.2 (2019-01-30)

0.9.1 (2019-01-30)

0.9.0 (2019-01-23)

Bug Fixes

  • list: Support null as a child element for ListItem (#584) (bf487d7)
  • ripple: add missing dependency to package.json (#612) (f6e4725)
  • ripple: Adds HTMLElement shim to fix regression for SSR projects (#592) (3aaf871)
  • text field: adds missing adapter method notifyIconAction on Icon (#600) (632896a)
  • top-app-bar: make top app bar props optional (#587) (1585c95)

Features

0.8.0 (2018-12-28)

Bug Fixes

  • infrastructure: add declaration package.json (#572) (8cb4b1b)
  • infrastructure: condense webpack configuration build step into one json file (#571) (512f3aa)
  • infrastructure: unit test code coverage for typescript (#487) (1170a1f)
  • list: minification-safe element type comparison (#509) (89f5fd2)
  • select: defensive foundation check before unmounting - also includes radio, checkbox, text-field (#512) (2ee4c80)
  • top-app-bar: foundation should be destroyed and reinitialized on variant change (#519) (58cfc6f)
  • lint for typings files (#577) (8f971a8)
  • remove prop-types from package.json (#576) (7f38952)

Features

BREAKING CHANGES

  • infrastructure: Remove <package-name>.es.js files. The alternate is now to use the index.tsx files.
  • ripple: withRipple is no longer the default export.

0.7.1 (2018-11-30)

Bug Fixes

  • added missing comma from golden.json (#426) (dfe44dc)
  • chips: update to v0.41.0 (#424) (e40fec6)
  • drawer: initialize foundation if props.open updates (#427) (36e6316)
  • drawer: replace focus trap with vanilla version (#437) (bd7433b)
  • drawer: update modal screenshot golden (#482) (ce0c314)
  • linear-progress: Add linear progress (#450) (f38d575)
  • select: added check for nativeControl element before calling props.setRippleCenter in NativeControl (#478) (5baad76)
  • tab-bar: set previousActiveIndex to props.activeIndex initially to avoid tab of undefined error (#428) (8e28944)
  • text-field: custom validation (#430) (f5c9c35)
  • text-field: uncomment test fixed from 0.35.0 (#404) (3a908ff)

Features

0.6.2 (2018-11-07)

Bug Fixes

  • checkbox: add focusable=false to svg for a11y (#375) (c7f3b97)
  • drawer: update readme and screenshots to support below top app bar (#397) (90adbbe)
  • infrastructure: increase screenshot timeout to decrease flakes (#373) (e96ca10)
  • layout-grid: remove unit test console warnings (#379) (408cdd2)
  • list: selectedIndex 0 isn't working (#387) (4e62aae)
  • text-field: added reference to input element (#414) (ea04dc6)
  • text-field: allow for input isValid override (#374) (7872856)
  • text-field: put foundation on state and do render input unless foundation is present (#353) (2cb5d64)
  • text-field: remove foundation.setValue call during onChange (#350) (36469f7)
  • top-app-bar: add FixedAdjust to npmignore (#371) (d4ad675)
  • top-app-bar: allow react elements in title (#376) (f6da361)

Code Refactoring

Features

  • infrastructure: add verify pkg main to dist script (#320) (459c6dd)

BREAKING CHANGES

  • list: Event handlers moved from list to list item. New props on list item for focus, follow href, toggle checkbox, and classnames/attributes passed down from list. Remove ID prop from list item.

0.6.0 (2018-10-24)

Bug Fixes

  • chips: added npmignore (#317) (ac99ac5)
  • chips: replace relative path with npm package (#297) (93ac25e)
  • icon-button: add main field to package.json (#300) (88d5e4e)
  • icon-button: add MIT license to files (#313) (97ecb3a)
  • icon-button: update main property (#319) (e79995d)
  • infrastructure: add more time to screenshot initial wait (#314) (375206e)
  • infrastructure: fix travis badge on readme (#331) (e637782)
  • infrastructure: speed up prerelease script (#288) (b77819f)
  • menu-surface: fix menu surface unit test typo (#315) (8b60622)
  • text-field: Add support for <textarea> (#118) (#266) (d9cff89)
  • text-field: floating label width calculation when notched (#347) (377f250)
  • top-app-bar: add fixed adjust component (#349) (f1d4be0)

Features

0.5.1 (2018-09-25)

Bug Fixes

  • line-ripple: stop calling foundation.setRippleCenter when argument is NaN (#287) (4bbc4fa)

0.5.0 (2018-09-25)

Bug Fixes

  • card: add missing hasRipple (#248) (#255) (d2f58d6)
  • chips: add chip leading icon class management (#281) (c638e79)
  • chips: remove handleRemove method for chipsUpdate method (#282) (8435079)
  • chips: use notifyRemoval and notifyInteraction adapter methods (#277) (ba433ea)
  • infrastructure: add the es5 @material/package/dist/mdc.package to externals (#223) (73fb45b)
  • ripple: react-ripple does not contain styles (#172) (#251) (ac0f87f)
  • tab: update readme and ref name in tab component (#226) (f18fda1)
  • tab-bar: add missing url from screenshot list (#264) (dd2f183)
  • tab-bar: Arrow keys should focus adjacent tab (#280) (54224c8)
  • tab-indicator: update component to work with mdc tab (#215) (bc41a8b)
  • tab indicator sliding animation broken (#273) (c436f58)

Features

BREAKING CHANGES

  • chips: Updated API for selectedChipIds and handleSelect props in ChipSet and id prop in Chip.

0.4.2 (2018-08-14)

0.4.1 (2018-08-13)

Bug Fixes

  • infrastructure: point all tests to es6 files for accurate test coverage (#198) (4959266)
  • ripple: add test to avoid computeBoundingRect error (#200) (769b15b)
  • screenshot increase timeout (#210) (e9a2089)
  • text-field: add missing prop style (#184) (ff9704d)
  • text-field: fix typo in readme (#197) (f88f180)
  • text-field: update isRtl to a prop (#195) (cd7c7c8)

Features

BREAKING CHANGES

  • text-field: In order for rtl to work on the Notched Outline component, isRtl will need to be passed in as boolean (default is false). Updating isRtl will result in a re-render.

0.4.0 (2018-07-30)

Bug Fixes

  • infrastructure: updated deploy steps to run with docker (#116) (a53fc7d)
  • downgraded to es2015 preset to work on ie11 (#133) (05c0184)
  • material-icon: removed blocking line and updated documentation (#155) (8f3cef5)
  • ripple: setState warning when unmounting the component (#112) (841a1c8)
  • text-field: move handleValueChange call when this.props.value updates (#170) (f46a34d)
  • top-app-bar: add material icon imports in screenshot tests (#168) (526400b)
  • point packages to MDC Web /dist ES5 files (#182) (9d387d3)

Chores

  • fab: Pass icon as a prop, not a child element (#159) (1569f97)

Features

  • button: Add an href prop to use anchor tag instead of button (#174) (0df9967)
  • chips: Add new component (#117) (410da30)
  • chips: Add selection to chips (#121) (3ef1123)
  • ripple: Call focus/blur handlers from foundation (#135) (c438333)

BREAKING CHANGES

  • fab: Please update your FAB to pass icon as a prop, not as a child element.
  • chips: Users should render Chip components directly instead of passing a labels prop to ChipSet.

0.3.0 (2018-06-25)

Bug Fixes

  • Moved importer code to webpack.util to share between screen shot test and main build. (aec8cc8)
  • travis and docker integration (#92) (e7f4497)
  • updated function name and tests (7c2794d)
  • line-ripple: Convert style name to camel case (#99) (2a5341c)
  • text-field: Added SASS importer to lookup the package folder first then fallback to default npm resolve. (bf7f849)
  • text-field: Added text-field to valid commit msg list (3922e2c)
  • text-field: Updated Input.js to use new public API of foundation (df0b5ed)

Features

  • Docker integration into Travis to decrease false negative screenshots (#91) (d8b670e)
  • updated all packages to 0.36.0 (#104) (a1d8b66)
  • infrastructure: add .npmignores to packages (#110) (ab7009d)
  • infrastructure: default npm entry point to ES5 (#108) (1f0446f)

0.2.0 (2018-06-01)

Bug Fixes

  • Remove scss extensions from @material/mdc-* imports (#62) (46b7f08)
  • button: Rename stroked to outlined (#74) (f612388)
  • infrastructure: fixed npm run build error for empty package directories (#85) (18666d4)
  • infrastructure: Make all components public (#43) (27a1ab1)
  • ripple: Trigger on key events (2248f26)

Features

0.1.0 (2018-05-09)

Bug Fixes

  • button: Update package.json (507298e)
  • card: Update package.json (fc7a4dd)
  • fab: Update package.json (efd4703)
  • floating-label: Update package.json (92cbf2c)
  • line-ripple: Update package.json (b6fc89c)
  • material-icon: Update package.json (18e2508)
  • notched-outline: Update package.json (8b18779)
  • ripple: Update package.json (044c308)
  • text-field: Update package.json (fda82fb)
  • top-app-bar: Update package.json (06e9d66)

Features

  • remote hosted screenshot testing (#12) (98bcdfe)
  • screenshot testing (#10) (5fd6d86)
  • fab: Add new tests for svg/img (1f536b7)
  • fab: Change node to element. (2b4960e)
  • fab: Remove empty fab from test. Add waitUntil idle to wait until the stylesheets finish (43e58d4)
  • fab: Update class name (96c2d61)
  • fab: Update for comments (9b041d6)
  • fab: Update for comments (676ae32)
  • fab: Update for lint (3748f31)
  • fab: Update package name (02b7140)