content logo

React Forms:

Drop Down Menu by React JS

You can use this code if you need a menu that displays an alert by clicking on any of its items. This theme code has a blue color. Clicking on the phrase in the middle of the page opens a menu whose items are white. By placing the mouse on any of the menu items, the color of the item changes. Click on any item at the top of the screen.

#

React Dropdown Code

#

React Form List Code

#

HTML Dropdown List

#

React Js Alert Box

<!-- This script got from frontendfreecode.com -->
<div id="app"></div><a style="font-size: 8pt; text-decoration: none" target="_blank" href="http://frontendfreecode.com">Free Frontend</a>
                                                                            
@import url('https://fonts.googleapis.com/css?family=Spectral');
html{
  align-items: center;
  background: #243b55;
  color: white;
  text-align:center;
  font-family: 'Spectral', serif;
  justify-content: center;
  height: 100%;
}
.Invisible{
  height: 100vh;
  left: 0;
  position: fixed;
  top: 0;
  width: 50%;
  margin-top:50px;
  z-index: -9999999;
}
.Menu{
  text-align:center;
}
.Click,
.Menu ul{
  cursor: pointer;
  margin-top:50px;
  text-align:center;
}
.Menu ul{
  border: 3px solid white;
  margin: 0 25%;
  padding: 20px;
}
.Menu ul li{
  list-style-type: none;
  padding: 10px;
}
.Menu ul li:hover{
  background: gray;
}
function _defineProperty(obj, key, value) {if (key in obj) {Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true });} else {obj[key] = value;}return obj;}class Application extends React.Component {
  constructor() {
    super();_defineProperty(this, "showMenu",
    () => this.setState({ showMenu: true }));_defineProperty(this, "hideMenu",
    () => this.setState({ showMenu: false }));this.state = { showMenu: false };}
  render() {
    return /*#__PURE__*/React.createElement("div", { className: "Nav" }, /*#__PURE__*/
    React.createElement("div", { onClick: this.showMenu, className: "Click" }, "Dropdown menu"),
    this.state.showMenu ? /*#__PURE__*/
    React.createElement("div", { className: "Menu" }, /*#__PURE__*/
    React.createElement("div", { onClick: this.hideMenu, className: "Invisible" }), /*#__PURE__*/
    React.createElement("ul", null, /*#__PURE__*/
    React.createElement("li", { onClick: () => alert('Click on Elem 1') }, "Elem 1"), /*#__PURE__*/
    React.createElement("li", { onClick: () => alert('Click on Elem 2') }, "Elem 2"), /*#__PURE__*/
    React.createElement("li", { onClick: () => alert('Click on Elem 3') }, "Elem 3"))) :
    null);
  }}
React.render( /*#__PURE__*/React.createElement(Application, null), document.getElementById('app'));
<script src='https://cdnjs.cloudflare.com/ajax/libs/react/0.13.0/react.min.js'></script>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<!-- This script got from frontendfreecode.com -->

<script src='https://cdnjs.cloudflare.com/ajax/libs/react/0.13.0/react.min.js'></script>
<style>
@import url('https://fonts.googleapis.com/css?family=Spectral');
html{
  align-items: center;
  background: #243b55;
  color: white;
  text-align:center;
  font-family: 'Spectral', serif;
  justify-content: center;
  height: 100%;
}
.Invisible{
  height: 100vh;
  left: 0;
  position: fixed;
  top: 0;
  width: 50%;
  margin-top:50px;
  z-index: -9999999;
}
.Menu{
  text-align:center;
}
.Click,
.Menu ul{
  cursor: pointer;
  margin-top:50px;
  text-align:center;
}
.Menu ul{
  border: 3px solid white;
  margin: 0 25%;
  padding: 20px;
}
.Menu ul li{
  list-style-type: none;
  padding: 10px;
}
.Menu ul li:hover{
  background: gray;
}
</style>

</head>
<body>
<div id="app"></div><div id="bcl"><a style="font-size:8pt;text-decoration:none;" href="http://www.devanswer.com">Free Frontend</a></div>
<script>
function _defineProperty(obj, key, value) {if (key in obj) {Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true });} else {obj[key] = value;}return obj;}class Application extends React.Component {
  constructor() {
    super();_defineProperty(this, "showMenu",
    () => this.setState({ showMenu: true }));_defineProperty(this, "hideMenu",
    () => this.setState({ showMenu: false }));this.state = { showMenu: false };}
  render() {
    return /*#__PURE__*/React.createElement("div", { className: "Nav" }, /*#__PURE__*/
    React.createElement("div", { onClick: this.showMenu, className: "Click" }, "Dropdown menu"),
    this.state.showMenu ? /*#__PURE__*/
    React.createElement("div", { className: "Menu" }, /*#__PURE__*/
    React.createElement("div", { onClick: this.hideMenu, className: "Invisible" }), /*#__PURE__*/
    React.createElement("ul", null, /*#__PURE__*/
    React.createElement("li", { onClick: () => alert('Click on Elem 1') }, "Elem 1"), /*#__PURE__*/
    React.createElement("li", { onClick: () => alert('Click on Elem 2') }, "Elem 2"), /*#__PURE__*/
    React.createElement("li", { onClick: () => alert('Click on Elem 3') }, "Elem 3"))) :
    null);
  }}
React.render( /*#__PURE__*/React.createElement(Application, null), document.getElementById('app'));
</script>

</body>
</html>
Preview