如何自定义react-popper箭头

时间:2019-07-19 19:10:42

标签: css reactjs bootstrap-4 react-popper

如何将箭头样式设置为与波普尔相同

import React from "react";
import ReactDOM from "react-dom";
import { Manager, Reference, Popper } from "react-popper";

function App() {
  return (
    <Manager>
      <Reference>
        {({ ref }) => (
          <button type="button" ref={ref}>
            Reference element
          </button>
        )}
      </Reference>
      <Popper placement="right">
        {({ ref, style, placement, arrowProps }) => (
          <div
            ref={ref}
            style={style}
            className={`popover show bs-popover-${"right"}`}
          >
            <div className="popover-inner bg-primary">Popper element</div>
            <div
              className="arrow bg-primary"
              ref={arrowProps.ref}
              style={arrowProps.style}
            />
          </div>
        )}
      </Popper>
    </Manager>
  );
}

ReactDOM.render(<App />, document.getElementById("root"));

代码沙箱:https://codesandbox.io/s/bold-shape-lomrm

1 个答案:

答案 0 :(得分:0)

首先,添加以下CSS:

.bs-popover-auto[x-placement^=right] .arrow::after, .bs-popover-right .arrow::after {
  border-right-color: #007bff;
}

bg-primary摆脱.arrow类,并给出以下样式:

style="top: -2px;"

预览

preview

演示: https://codesandbox.io/s/eager-wu-h337q