React-Bootstrap
Bootstrap 5 components built with React.
Bootstrap compatibility
React-Bootstrap is compatible with various versions of Bootstrap. As such, you need to ensure you are using the correct combination of versions.
See the below table on which version of React-Bootstrap you should be using in your project.
Bootstrap Version | React-Bootstrap Version | Documentation |
---|---|---|
v5.x | 2.x | Link |
v4.x | 1.x | Link |
v3.x | 0.33.x (not maintained) | Link |
Migrating from previous versions
Bootstrap 4 to Bootstrap 5
If you would like to update React-Bootstrap within an existing project to use Bootstrap 5, please read our docs for migrating to React-Bootstrap V2.
Bootstrap 3 to Bootstrap 4
If you would like to update React-Bootstrap within an existing project to use Bootstrap 4, please read our docs for migrating to React-Bootstrap V1.
Related modules
- react-router-bootstrap – Integration with React Router
- Awesome React Bootstrap Components - Additional components like off-canvas navbar, switch and sliders.
Local setup
Yarn is our package manager of choice here. Check out setup instructions here if you don't have it installed already. After that you can run yarn run bootstrap
to install all the needed dependencies.
From there you can:
- Run the tests once with
yarn test
(Or run them in watch mode withyarn run tdd
). - Start a local copy of the docs site with
yarn start
- Or build a local copy of the library with
yarn run build
CodeSandbox Examples
Click here to explore some React-Bootstrap CodeSandbox examples.
Click here to automatically open CodeSandbox with the React-Bootstrap CodeSandbox Examples GitHub Repository as a workspace.
Contributions
Yes please! See the contributing guidelines for details.
Fix arbitrary prop passthrough to DOM nodes.
@jimfb and @gaearon were kinda enough to reach out and warn us that RB will have a lot of warnings in React v15.2.0, of which, a release is imminent.
The problem is that in preparation for removing the DOM attribute whitelist, React has started to warn when props that are not DOM attributes are passed through to DOM nodes. This (AFAIK) to help for folks to clean up code before those attributes are suddenly applied to the DOM nodes in a later version when the whitelist is removed.
@react-bootstrap/collaborators If anyone has time to start talking this in part (or whole) this might be less of a chore if a bunch of folks work on it. We also need to decide what the best way to ensure that we do not break existing API's by being too restrictive in what we pass through.
Concerns
I'm not sure if any of these cases exist (here) but I am concerned about API's that require carte-blanche passthrough of props to a child that may or may not a DOM node. Presumably in those cases we can either defer to the User to use a component, or make sure to remove "own" props before passing through.
This also effectively means that API's like
dropdown
which allow for using the throwawaybsRole
prop to indicate type to the parent no longer work for DOM nodes. That sort of sucks, that was a really great side-effect feature of that API.react-bootstrap's Modal does not work with React 16
Look like the recent react's update has cause react-bootstrap modal to stop working. Here are the errors:
This issue is also discussed on
react-overlays
https://github.com/react-bootstrap/react-overlays/issues/188
Modal has issues when invoked in a class: Cannot read property 'getDialogElement' of null
Hey all,
Im trying to use the modal in a react class and I'm running into
Cannot read property 'getDialogElement' of null
andCannot read property 'remove' of null
.here is my code snippet, lifted directly from your site, but adopted for a component:
When this code executes however I get the first error on show and the transition animation does not play and its this line
var dialogNode = this._modal.getDialogElement();
in Modal.js that triggers it, because _modal isnull
. Breakpointing through the code, the issue seems to be happening because when the render method is called. When the page first loads, the render method is called, and this functionref={c => { this._modal = c; }}
is invoked withc
being the Modal object. However when the state changes (in this case pushing the button,c
resolved to null and overrides the initial prop. Any functions that have to call Modal properties on _modal now fail.It's very possible I missed something here and there is an issue with my code, but I can't seem to get this working properly within my context.
Impose airbnb linting with exceptions
just compare with https://github.com/react-bootstrap/react-bootstrap/pull/1176 11 vs 22 exclusions :smile:
It seems
semistandard
is way less stricter and suits more forR-B
.Invariant violation when adding Navbar
I'm getting this error message
when adding the following code:
React 0.12 support
Provide React 0.12 support in all react-bootstrap components.
BREAKING CHANGES: It's no longer possible to use key indiscriminately within React components, so I had to make the following changes to component props:
Panel: key -> eventKey MenuItem: key -> eventKey NavItem: key -> eventKey TabPane: key -> eventKey ListGroupItem: key -> eventKey
Comments or help finishing this off is welcome.
Popper: CSS "margin" styles cannot be used to apply padding warning when using OverlayTrigger with Popover
Describe the bug
When you click on
<OverlayTrigger>button here</OverlayTrigger>
it opens a popover, but an error appears in a console:"Popper: CSS "margin" styles cannot be used to apply padding between the popper and its reference element or boundary. To replicate margin, use the
offset
modifier, as well as thepadding
option in thepreventOverflow
andflip
modifiers."To Reproduce
Steps to reproduce the behavior:
npx create-react-app sandbox
yarn add [email protected]
Reproducible Example
Codesandbox, nor jsfiddle didn't work at the time i wrote this issue. Heres an example markup:
Click on the button and watch your console.
Expected behavior
No warning/error messages should be present in a console.
Screenshots
Environment (please complete the following information)
Change Panel and ListGroupItem API
Per the documentation: http://react-bootstrap.github.io/components.html#panels, when using a panel, unless you specifically supply the header prop some heading tags, it will print the title area as normal text within the panel-heading div. If you wrap that Panel in an Accordion, supplying just a string to Panel's header prop will suddenly output a title wrapped in an H4.
I think this is inconsistent behavior. Is there any reason why it specifically creates an H4 tag in this instance? I would like to have an accordion panel where the heading text is just normal text and not an H4.
Panel.js:187 looks like it could be the culprit.
To reproduce create:
Note that the title is rendered as normal text. Then try:
The title now automatically becomes an H4
Overlay Overhaul
Moving the conversation from #811 into a PR b/c I think it may help provide some visibility into the code changes I am thinking about here. be warned this is a really long note
We have two major API's that are Changing: Modals, Overlays (tooltips/popovers)
Consolidations
Portal
componentPortal
component, just renders its children into acontainer
fixes #404Modals and Overlays share some common functions underneath, and Users have come to use our OverlayMixin, the new
Portal
Component offers the same functionality in a way that works for both createClass or plain class consumersModals
ModalTrigger
- fixes #397, fixes #616title
andcloseButton
props on Modal (moved to ModalHeader)onRequestHide
prop renamed toonHide
(more idiomatic with our callbacks)ModalHeader
ModalTitle
ModalBody
ModalFooter
Api
new components are exported on the Modal component Automatically for ease of use, or can be imported from lib if the user wants. Body, Footer, and Title are just convenient wrappers of
<div className='modal-part'/>
and Modal Header will auto wire the closeButton click to the parentonHide
.I think its safe to remove (deprecated for now) ModalTrigger, it is a slight convenience over handling the state yourself ,but since you don't generally have 10s of modals in a component at once (as with tooltips potentially) I say we prefer the React philosophy of explicitness over abstraction here.
By explicitly specifying the Header, users get more customization options and better potential accessibility (
aria-labelledby
above). We can gracefully deprecate the current api, by checking if a user provides atitle
prop in the Modal and auto adding the new Header Component to the children, so no breaking changes.Overlays
The tooltips and popovers (from here on out "Overlays") present some interesting issues Modals do not.
Goals for the API
My Proposed path here is to ultmately end up with a declarative Overlay Component that can be completely controlled in terms of positioning, and display (show/hide). I think that looks something like the Modals above
To acheive this though, both the render-to-container (show/hide), and positioning logic need to be removed from the
OverlayTrigger
Component and moved downstream. me and @taion have had a few long conversations on gitter about how far down to move it.Before that though I have abstracted out that logic into seperate Components, we've already seen
Portal
as used by Modal, and the to-be-better-named:Position
Component, for calculating an offset based on the target and container.that leaves us with the following as the implementation of an Overlay:
Which feels like a lot of boilerplate for making custom Overlays. To help with that I am bundling both of these components up into an Overlay Component which makes it a bit better...
This feels a bit verbose to me but probably reasonable for Custom Overlays. It also means that the Popover and Tooltip Components are no longer "dumb" static markup components, which enables the declarative api way up page. I think that this is worth it, the Alternative is that we needto abandon the declartive api and put the logic back in OverlayTrigger or write this when we want the declarative syntax:
I find that less optimal than just having the PopOver component but it does have an advantage that @taion thinks is worth it. If we do it this way OverlayTrigger can jsut wrap its
overlay
prop in anOverlay
Component, and then you can specify static markup to it, without it needing to be a special kind of Component.Simplier Custom Overlays
which is less verbose than:
Simplier Declarative Overlays
GET TO THE POINT ALREADY THIS PR IS SOOOOOOOO LONG
Which Overlay Api do we go with?
Bootstrap 5 support
Issue which keeps track of issues which are persistent / blocking before we can publish a version with Bootstrap 5 compatibility.
I can go ahead with creating the branch, bumping Bootstrap to v5 and connecting it with Netlify as soon as #5150 is merged. Then we have to go over the upstream changes etc.
Regarding Netlify and GitHub Pages, maybe use https://react-bootstrap-v5.netlify.app as soon its in alpha and once its stable move it over to the main name and v4 to https://react-bootstrap-v4.netlify.app.
cc @jquense @taion @bpas247
Add eventType to onToggle and source for handleClose
This PR attempts to resolve #1490. The main things that I changed are:
I tried it out locally in my own app and I was able to override the default closing of the dropdown by creating my own state that I called
dropdownOpen
that I passed in as theopen
prop to the Dropdown component. I created ahandleToggle
function that I pass in as theonToggle
prop which only closes whenopen
isfalse
and the event that closed it isclose
. Here's what my handleToggle looks like:Here's what you get when you console.log the inputs to onToggle:
I didn't know how to write a test for this so if you could advise me on how I could then I'll add it to this PR, thanks!
Support for Bootstrap v5.3
Is your feature request related to a problem? Please describe
Bootstrap v5.3 brings quite a good change i.e, bringing color modes in which the developer can change the theme (light or dark) of a component. This feature is helpful as it prevents writing extra styles.
Describe the solution you'd like
I really will like this feature as it makes React developers write less code.
Describe alternatives you've considered
No response
Additional context
Though Bootstrap v5.3 is currently in alpha (at the time of speaking), still I will really like you to add support for Bootstrap v5.3.
Modal re-render itself and looses focus on input change
Prerequisites
Describe the bug
When I change input values, modal re-render and loose focus on input.
Expected behavior
It should behave normal as form input behaves without react-bootstrap Modal.
To Reproduce
Reproducible Example
You can see code here, https://codesandbox.io/s/react-bootstrap-modal-issue-reproduction-dmjvud?file=/src/Products.js
Screenshots
No response
What operating system(s) are you seeing the problem on?
macOS
What browser(s) are you seeing the problem on?
Chrome, Safari
What version of React-Bootstrap are you using?
2.7.0
What version of Bootstrap are you using?
5.2.3
Additional context
No response
Docs: link navigation doesn't work properly
Prerequisites
Describe the bug
The "sticky top" anchor in in https://react-bootstrap.github.io/components/navbar/#overview navigates to the path
/#undefined
which doesn't change anything (basically its an anchor tag linked to nothing):https://react-bootstrap.github.io/components/navbar/#undefined
IMO the "Sticky top" anchor should be removed and let "Placement" without any sub-anchor, since it is already a section that fits alone one one's screen:
Expected behavior
Expected clicking on the link would navigate me to the specific section
To Reproduce
Reproducible Example
see above
Screenshots
see above
What operating system(s) are you seeing the problem on?
No response
What browser(s) are you seeing the problem on?
No response
What version of React-Bootstrap are you using?
2.7.0
What version of Bootstrap are you using?
5.2
Additional context
all above
chore(deps): bump json5 from 1.0.1 to 1.0.2 in /www
Bumps json5 from 1.0.1 to 1.0.2.
Release notes
Sourced from json5's releases.
Changelog
Sourced from json5's changelog.
... (truncated)
Commits
a62db1e
1.0.2e0c23fe
docs: update CHANGELOG for v1.0.262a6540
fix: add proto to objects and arraysDependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting
@dependabot rebase
.Dependabot commands and options
You can trigger Dependabot actions by commenting on this PR:
@dependabot rebase
will rebase this PR@dependabot recreate
will recreate this PR, overwriting any edits that have been made to it@dependabot merge
will merge this PR after your CI passes on it@dependabot squash and merge
will squash and merge this PR after your CI passes on it@dependabot cancel merge
will cancel a previously requested merge and block automerging@dependabot reopen
will reopen this PR if it is closed@dependabot close
will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually@dependabot ignore this major version
will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)@dependabot ignore this minor version
will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)@dependabot ignore this dependency
will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)@dependabot use these labels
will set the current labels as the default for future PRs for this repo and language@dependabot use these reviewers
will set the current reviewers as the default for future PRs for this repo and language@dependabot use these assignees
will set the current assignees as the default for future PRs for this repo and language@dependabot use this milestone
will set the current milestone as the default for future PRs for this repo and languageYou can disable automated security fix PRs for this repo from the Security Alerts page.
chore(deps): bump json5 from 1.0.1 to 1.0.2
Bumps json5 from 1.0.1 to 1.0.2.
Release notes
Sourced from json5's releases.
Changelog
Sourced from json5's changelog.
... (truncated)
Commits
a62db1e
1.0.2e0c23fe
docs: update CHANGELOG for v1.0.262a6540
fix: add proto to objects and arraysDependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting
@dependabot rebase
.Dependabot commands and options
You can trigger Dependabot actions by commenting on this PR:
@dependabot rebase
will rebase this PR@dependabot recreate
will recreate this PR, overwriting any edits that have been made to it@dependabot merge
will merge this PR after your CI passes on it@dependabot squash and merge
will squash and merge this PR after your CI passes on it@dependabot cancel merge
will cancel a previously requested merge and block automerging@dependabot reopen
will reopen this PR if it is closed@dependabot close
will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually@dependabot ignore this major version
will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)@dependabot ignore this minor version
will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)@dependabot ignore this dependency
will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)@dependabot use these labels
will set the current labels as the default for future PRs for this repo and language@dependabot use these reviewers
will set the current reviewers as the default for future PRs for this repo and language@dependabot use these assignees
will set the current assignees as the default for future PRs for this repo and language@dependabot use this milestone
will set the current milestone as the default for future PRs for this repo and languageYou can disable automated security fix PRs for this repo from the Security Alerts page.
`bootstrap modal` rendered slow and laggy on Chrome
Prerequisites
Describe the bug
Component with
bootstrap modal
being used is rendered slow and laggy on Chrome but works smoothly on Safari. Do you have any idea why or is this a bug?Expected behavior
bootstrap modal
works the same on all major browsers.To Reproduce
No response
Reproducible Example
Will provide later.
Screenshots
No response
What operating system(s) are you seeing the problem on?
macOS
What browser(s) are you seeing the problem on?
Chrome
What version of React-Bootstrap are you using?
5.2.3
What version of Bootstrap are you using?
5.2.3
Additional context
No response