[英]react-bootstrap-typeahead default styling
I am trying to use react-bootstrap-typeahead in my project.我正在尝试在我的项目中使用 react-bootstrap-typeahead。 The problem is that formatting looks pretty awful.问题是格式化看起来很糟糕。 I tried running the exact same code in an online sandbox.我尝试在在线沙箱中运行完全相同的代码。 There it looks fine.那里看起来不错。
At first i thought that the sandbox is applying explicit styles, but that does not seem to be the case.起初我认为沙盒正在应用显式样式,但似乎并非如此。 As far as i can tell, it is using the default styling of the typeahead competent instead of applying heavy formatting.据我所知,它使用的是 typeahead 主管的默认样式,而不是应用重格式。 https://codesandbox.io/s/9jq9jyzmry https://codesandbox.io/s/9jq9jyzmry
I suspect that something in my app is overriding the styling used by the typeahead and leading to it being improperly rendered.我怀疑我的应用程序中的某些东西覆盖了预输入使用的样式并导致它被不正确地呈现。
I realize it is possible to apply custom formatting to the typeahead, but that feels laborious.我意识到可以将自定义格式应用于预输入,但这感觉很费力。 Is there a way to force default styling on the typeahead?有没有办法强制预先输入的默认样式?
For reference, here's the code:作为参考,下面是代码:
import React, { useState } from 'react';
import { Typeahead } from 'react-bootstrap-typeahead';
const MyPicker = () => {
const [selected, setSelected] = useState([]);
const handleChange = (sel) => setSelected(sel);
return (
<div>
<Typeahead
multiple
clearButton
id="my-typeahead"
labelKey="fullname"
onChange={handleChange}
options={[
{
fullname: 'Apple',
},
{
fullname: 'Banana',
},
{
fullname: 'Peach',
},
{
fullname: 'Zucchini',
},
]}
placeholder="Select options..."
selected={selected}
/>
</div>
);
};
export default MyPicker;
Figured it based on this question: CSS not loading correctly With React-bootstrap-typeahead根据这个问题想出来: CSS not loading correct With React-bootstrap-typeahead
The actual solution was to run npm install bootstrap
on my project and then add import 'bootstrap/dist/css/bootstrap.min.css';
实际的解决方案是在我的项目上运行npm install bootstrap
然后添加import 'bootstrap/dist/css/bootstrap.min.css';
to my component.到我的组件。
Still don't quite understand why that import is not needed in the sandbox environment.仍然不太明白为什么在沙盒环境中不需要导入。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.