简体   繁体   English

单击按钮时我想要模态

[英]i want modal when click on button

hi guys i am new in react js Am trying to build a small modal application, in this application i want to popup when i click on trigeer buttton, i did but not working my method if anyone know please tell me how can i solve this problem大家好,我是 React js 的新手 我正在尝试构建一个小型模态应用程序,在此应用程序中,我想在单击 trigeer 按钮时弹出,我做了但没有使用我的方法,如果有人知道,请告诉我如何解决这个问题

modal.js modal.js

This is my form where i want to popup when i click on trigger button这是我点击触发按钮时要弹出的表单

import React, { useState } from 'react';
import './Modal.css';
import Popup from 'reactjs-popup';
import Pop from './Pop';

const Modal = () => {

    const [mail, setEmail] = useState('');
    const [password, setPassword] = useState('');

    const handleChange = (e) => {
        e.preventDefault();
        if (password === "") {
            return alert("please Enter Email and Password")
        }
        else {
            return <Popup trigger={
                <Pop />
            }>
            </Popup>

        }

    }


    return (
        <div>
            <form>
                <div class="form-group">
                    <label for="exampleInputEmail1">Email address</label>
                    <input type="email"
                        class="form-control"
                        id="exampleInputEmail1"
                        aria-describedby="emailHelp"
                        placeholder="Enter email"
                        value={mail}
                        onChange={(e) => setEmail(e.target.value)}
                        required />
                </div>
                <div class="form-group">
                    <label for="exampleInputPassword1">Password</label>
                    <input type="password"
                        class="form-control"
                        id="exampleInputPassword1"
                        placeholder="Password"
                        value={password}
                        onChange={(e) => setPassword(e.target.value)}
                        required />
                </div>
                <button type="submit" class="btn btn-primary" onClick={handleChange}>Trigger</button>
            </form>
        </div>
    )
}

export default Modal;

pop.js pop.js

 import React from 'react'
    
    const Popup = () => {
        return (
            <div>
                <button type="button" class="btn btn-primary" data-toggle="modal" data-target="#exampleModal">
                    Submit
                </button>
                <div class="modal fade" id="exampleModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
                    <div class="modal-dialog" role="document">
                        <div class="modal-content">
                            <div class="modal-header">
                                <h5 class="modal-title" id="exampleModalLabel">Modal Title</h5>
                                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                                    <span aria-hidden="true">&times;</span>
                                </button>
                            </div>
                            <div class="modal-footer" style={{ display: 'flex', justifyContent: 'space-around' }}>
                                <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
                                <button type="button" class="btn btn-primary">Save changes</button>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        )
    }
    
    export default Popup;

You can use react bootstrap modal component here.您可以在此处使用反应引导模式组件。

import React, {useState, setShow } from 'react'
import {Modal} from 'react-bootstrap';


const myModal = () => {

    //handeling the modal open & close
    const [show, setShow] = useState(false);
    const handleShow = () => setShow(true);
    const handleClose = () => setShow(false);


   

    return (
       
        <>
            //this the button that triggers the modal
            <button onClick={handleShow}> Show Modal </button>

        

            <Modal className="my-modal" show={show} onHide={handleClose}>

                <Modal.Header closeButton className="mymodal-head">
                    <Modal.Title className="mymodal-title"><h4>The Modal</h4></Modal.Title>

                </Modal.Header>

                <Modal.Body className="mymodal-body">
//add your input fields and labels here
                    <input/>
                </Modal.Body>

                <Modal.Footer className="mymodal-footer">
//add your submit button here
                    <button> submit </button>
                </Modal.Footer>

            </Modal>


            
        </>
  
    )
}

Hope this helps: Feel free to ask me if you have any issues with the modal :)希望这会有所帮助:如果您对模态有任何问题,请随时问我 :)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我想在我的表格上添加编辑按钮并在单击演示模式按钮时打开 model 上的表单? - I want to add edit button on my table and open the form on model when click demo modal button? 单击按钮时渲染模态-React - Render a modal when I click a button - React 单击删除按钮时如何打开模式? - How can I open the modal when I click the delete button? 仅当我单击输入时,模态 window 才会关闭 Escape 按钮 - Modal window closing on Escape button only when i click on input 当用户单击共享按钮时,我想共享此 JSON DATA - I want to share this JSON DATA when user click on share button 单击按钮时如何获取我想要的 select 数据(React JS) - How to select data that i want when click button (React JS) 当我点击 <Link > 我想在React Router v4.x中设置一个确认模式 - when i click <Link >, I want to set a confrm modal before it works, in react router v4.x 我有一个提交按钮,当我点击提交按钮时,我想重定向到另一个路由器链接 - i have a submit button that i want to redirect to another router link when i click on submit button 单击删除按钮,我想要图像的ID - I want id of image on click of delete button 单击特定按钮ID时,如何在reactstrap模态中传递数据? - How can i pass data in reactstrap modal when specific button id is click?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM