React-Bootstrap Close Button API Last Updated : 23 Jul, 2024 Comments Improve Suggest changes Like Article Like Report React-Bootstrap close button API is a way to import Close Button provided by React Bootstrap. In this article we are going to explore Close Button API. Close button is used to close a dialog box or pop up in React Bootstrap.Close Button Props:variant: It is used for rendering the button in different colors. By default, It will use a dark color.onClick: The callback function when you click the button.aria-label: It shows the relevant information about the close button.Syntax:import CloseButton from 'react-bootstrap/CloseButton'Example 1: JavaScript // App.js import React from 'react'; import TodoList from './TodoList'; function App() { return ( <div className='App'> <h1 className="text-center"> React To- Do List </h1> <TodoList /> </div> )} export default App; JavaScript // TodoList.js import React, { useState } from 'react'; import { Container, InputGroup, FormControl, Button, ListGroup, CloseButton } from 'react-bootstrap'; const TodoList = () => { const [todos, setTodos] = useState([]); const [task, setTask] = useState(''); const handleAddTodo = () => { if (task.trim() !== '') { setTodos([...todos, task]); setTask('')}}; const handleRemoveTodo = (index) => { const newTodos = [...todos]; newTodos.splice(index, 1); setTodos(newTodos);}; return ( <Container className="mx-auto" style={{ maxWidth: '400px' }}> <InputGroup className="mb-3"> <FormControl type="text" placeholder="Add a new task" value={task} onChange={ (e) => setTask(e.target.value)} /> <Button variant="primary" onClick={handleAddTodo}> Add </Button> </InputGroup> <ListGroup> {todos.map((todo, index) => ( <ListGroup.Item key={index}> {todo} <CloseButton style={{ float: "right", marginLeft: "5px", fontWeight: "bold", cursor: "pointer"}} onClick={() => handleRemoveTodo(index)} /> </ListGroup.Item>))} </ListGroup> </Container>)}; export default TodoList; Output:outputExample 2: JavaScript // App.js import React from 'react'; import MyForm from './MyForm'; function App() { return ( <div className='App'> <MyForm /> </div>)} export default App; JavaScript // MyForm.js import React, { useState } from 'react'; import { Button, Form, Modal, CloseButton } from 'react-bootstrap'; function MyForm() { const [showForm, setShowForm] = useState(true); const [inputValue, setInputValue] = useState(''); const handleClose = () => setShowForm(false); const handleSubmit = (e) => { e.preventDefault(); alert('Submitted: ' + inputValue)}; return ( <div> <Modal show={showForm} onHide={handleClose}> <Modal.Header> <Modal.Title>Form</Modal.Title> <CloseButton onClick={handleClose} /> </Modal.Header> <Modal.Body> <Form onSubmit={handleSubmit}> <Form.Group controlId="formBasicText"> <Form.Label>Text Input</Form.Label> <Form.Control type="text" placeholder="Enter text" value={inputValue} autoComplete='off' onChange={(e) => setInputValue (e.target.value)}/> </Form.Group> <Button style={{ marginTop: "20px" }} variant="primary" type="submit"> Submit </Button> </Form> </Modal.Body> </Modal> </div> )} export default MyForm; Output:Reference: https://react-bootstrap.netlify.app/docs/components/close-button/#api Create Quiz Comment N neeraj3304 Follow 0 Improve N neeraj3304 Follow 0 Improve Article Tags : Web Technologies ReactJS Geeks Premier League React-Bootstrap Geeks Premier League 2023 +1 More Explore React FundamentalsReact Introduction6 min readReact Environment Setup3 min readReact JS ReactDOM2 min readReact JSX5 min readReactJS Rendering Elements3 min readReact Lists4 min readReact Forms4 min readReactJS Keys4 min readComponents in ReactReact Components4 min readReactJS Functional Components4 min readReact Class Components3 min readReactJS Pure Components4 min readReactJS Container and Presentational Pattern in Components2 min readReactJS PropTypes5 min readReact Lifecycle7 min readReact HooksReact Hooks8 min readReact useState Hook5 min readReactJS useEffect Hook5 min readRouting in ReactReact Router5 min readReact JS Types of Routers10 min read Advanced React ConceptsLazy Loading in React and How to Implement it ?4 min readReactJS Higher-Order Components5 min readCode Splitting in React4 min readReact ProjectsCreate ToDo App using ReactJS3 min readCreate a Quiz App using ReactJS4 min readCreate a Coin Flipping App using ReactJS3 min readHow to create a Color-Box App using ReactJS?4 min readDice Rolling App using ReactJS4 min readGuess the number with React3 min read Like