React-bootstrap Dropdown menu incorrectly aligned / positioned from translate3d property - react-bootstrap

I'm using a React-bootstrap (v1.5.2) dropdown component passing in a custom toggle component, and the dropdown menu renders correctly upon the first click, but subsequent renderings of the dropdown menu causes the menu to appear way out of alignment with the toggle button. It appears that a CSS property, translate3D, mis-calculates the position for the dropdown menu beginning with the second render of the dropdown's menu. I've also noticed that the CSS data attribute, data-popper-placement, changes from its initial value of "bottom-end" to "bottom-start" after the first click on the dropdown button. I'm following the code pattern suggested in the React-bootstrap dropdown docs for custom components, and like I said before, the dropdown menu renders correctly for the first button click.
<Header>
{(headerFixed) => {
return (
<Fragment>
<HomePageNav />
<AssembledDropdownMenu headerFixed={headerFixed}>
{(toggle, setToggleState) => {
return (
<Dropdown
className="d-none d-lg-inline"
onToggle={setToggleState}
>
<Dropdown.Toggle as={toggle} />
<Dropdown.Menu
style={{
borderRadius: "16px",
boxShadow: "0 0 12px 0 rgba(0, 0, 0, 0.2)",
}}
align="right"
popperConfig={{
placement: "bottom-end",
modifiers: [
{
name: "offset",
options: {
offset: [0, 10],
},
},
],
}}
>
<Dropdown.Item href="#/action-1">Action</Dropdown.Item>
<Dropdown.Item href="#/action-2">
Another action
</Dropdown.Item>
<Dropdown.Item href="#/action-3">
Something else
</Dropdown.Item>
</Dropdown.Menu>
</Dropdown>
);
}}
</AssembledDropdownMenu>
</Fragment>
);
}}
</Header>
import React, { Fragment, useState } from "react";
import Image from "next/image";
import styled from "styled-components";
export default function AssembledDropdownMenu({ headerFixed, children }) {
let [toggleState, setToggleState] = useState(false);
let toggle = React.forwardRef(({ children, onClick }, ref) => {
return (
<StyledButton
ref={ref}
onClick={(evt) => {
evt.preventDefault();
onClick(evt);
}}
className={
headerFixed ? (toggleState ? "fixed selected" : "fixed") : void 0
}
id="dropdown-custom"
data-display="static"
>
<div>
<Image
layout="fixed"
width={16}
height={16}
src={headerFixed ? "/icons-menu_b.svg" : "/icons-menu_w.svg"}
/>
</div>
<div>
<Image
layout="fixed"
width={24}
height={24}
src={headerFixed ? "/icons-profile_b.svg" : "/icons-profile_w.svg"}
/>
</div>
</StyledButton>
);
});
return children(toggle, setToggleState);
}
const StyledButton = styled.button`
display: flex;
flex-flow: row nowrap;
flex: 0 0 auto;
width: 88px;
height: 40px;
margin: 3px 165px 12px 0px;
padding: 8px 18px;
border-radius: 32px;
box-shadow: 0 3px 12px 0 rgba(0, 0, 0, 0.5);
border: solid 1px rgba(255, 255, 255, 0.5);
background-color: rgba(255, 255, 255, 0.25);
&.fixed {
box-shadow: none;
border: solid 1px #cccccc;
background-color: #ffffff;
}
&.fixed.selected {
box-shadow: 0 3px 12px 0 rgba(0, 0, 0, 0.2);
/*border: solid 1px #cccccc;
background-color: #ffffff;*/
}
& > div {
width: 16px;
height: 16px;
margin: -6px 12px 4px 0;
object-fit: contain;
}
& div + div {
width: 24px;
height: 24px;
margin: -2px 0 0 3px;
object-fit: contain;
}
`;

Related

How to style dropdown with styled-components

I am using React JS + Typescript for my app. For styling I am using styled-components. I am really new in styled components. I have created one dropdown. The logic works fine but the UI looks horrible. I uploaded my code in Code sand box. I want design my Dropdown like Tailwind. But since I am new styled-components, I just don't know how to do that.
This is my dropdown component
import React, { useState } from "react";
import styled from "styled-components";
import Arrow from './Arrow.svg'
const Wrapper = styled.div<
{
active: boolean;
}
>`
text-align: left;
width: 100%;
color: #bfc5cd;
font-size: 16px;
font-weight: 300;
position: relative;
margin: 2em 0;
#media (min-width: 400px) {
max-width: 300px;
}
svg {
fill: #798697;
transition: all 0.2s ease;
}
${props =>
props.active
? `
svg {
transform: rotate(180deg);
}
`
: ``}
`;
const MenuLabel = styled.span`
display:inline-block;
color: grey;
border: 1px solid green;
background: white;
box-shadow: 0 0 5px -1px rgba(0,0,0,0.2);
cursor:pointer;
vertical-align:middle;
max-width: 100px;
padding: 40px 40px;
font-size: 12px;
text-align: center;
border: 1px solid ${({ theme }) => theme.inputBorderColor};
&:focus {
outline: none;
box-shadow: 0px 0px 0px 1px ${({ theme }) => theme.inputBorderColorActive};
border: 1px solid ${({ theme }) => theme.inputBorderColorActive};
}
`;
const ItemList = styled.div`
color: #798697;
background: white;
line-height: 30px;
padding: .25em 2em .25em 2em;
cursor: defaul;
user-select: none;
transition: all .25s ease;
&:hover,
&.selected {
background: #F7F7F7;
color: #4A4A4A;
}
`;
export interface IOptions {
label: string;
value: number;
}
export interface IDropdown {
labelDefault: string;
options: IOptions[];
}
const Dropdown = ({ labelDefault, options }: IDropdown) => {
const [isOpened, setIsOpened] = useState(false);
const [selectedOption, setSelectedOption] = useState("");
const [label, setLabel] = useState("");
const handleSelectedItem = (obj: any) => {
setSelectedOption(obj.value);
setLabel(obj.label);
setIsOpened(!isOpened);
};
return (
<Wrapper active={isOpened}>
<MenuLabel onClick={() => setIsOpened(!isOpened)}>
{selectedOption ? label : labelDefault}
</MenuLabel>
<ul
style={
isOpened
? {
display: "block",
listStyleType: "none"
}
: { display: "none" }
}
>
{options.map(el => (
<ItemList
key={el.value.toString()}
onClick={() => handleSelectedItem(el)}
>
{el.label}
</ItemList>
))}
</ul>
</Wrapper>
);
}
export default Dropdown;
This is the parent component
import * as React from "react";
import Dropdown from "./dropdown";
const MockData = [
{ label: "one", value: 1 },
{ label: "two", value: 2 },
{ label: "three", value: 3 }
];
export default function App() {
return (
<div className="App">
<h1>Hello CodeSandbox</h1>
<Dropdown labelDefault="Select a label" options={MockData} />
</div>
);
}

I can't adjust the HTML input placeholder font by using SCSS, is there some code is wrong?

I can't adjust the HTML input placeholder font by using SCSS, but it looks like didn't word, is there some code is wrong ?
enter image description here
<div class="input">
<p>身高 cm</p>
<input type="text" placeholder="請輸入身高">
<p>體重 kg</p>
<input type="text" placeholder="請輸入體重">
</div>
.input {
display: flex;
justify-items: center;
flex-direction: column;
align-items: flex-start;
p {
font-size: 18px;
color: #FFD366;
margin-bottom: 7px;
}
input {
background: rgba(255, 255, 255, 0.18);
border: 2px solid #FFD366;
border-radius: 10px;
width: 250px;
height: 40px;
margin-bottom: 23px;
::-webkit-input-placeholder{
font-size: 24px;
color: rgba(255, 255, 255, 0.50);
}
}
}
You forgot the SCSS parent selector &:
input {
/* ... */
&::-webkit-input-placeholder{
font-size: 24px;
color: rgba(255, 255, 255, 0.50);
}
}

Bootstrap Tags input with Objects as tags typehead Free input not working

I am using bootstrap-tags input (Objects as tags - https://bootstrap-tagsinput.github.io/bootstrap-tagsinput/examples/) for my tags input.
It is working fine with Objects as tags for auto complete suggestions.
But I am trying to active Free input too. So, if tags not in the autosuggest list then it allow to add new tags.
Here is my code:
var tags = new Bloodhound({
datumTokenizer: Bloodhound.tokenizers.obj.whitespace('text'),
queryTokenizer: Bloodhound.tokenizers.whitespace,
prefetch: {
ttl: 1,
url:'[Json File Path]'
}
});
tags.initialize();
var elt = $('input#tags');
elt.tagsinput({
tagClass: 'badge badge-primary',
itemValue: function(item) {
return item.id;
},
itemText: 'text',
freeInput: true,
typeaheadjs: {
name: 'tags',
displayKey: 'text',
source: tags.ttAdapter()
}
});
Sample Json:
[{"id":15,"text":"money"},{"id":14,"text":"startup"},{"id":13,"text":"inspiration"},{"id":12,"text":"success"},{"id":11,"text":"challenge"}]
jS
var citynames = new Bloodhound({
datumTokenizer:
Bloodhound.tokenizers.obj.whitespace('name'),
queryTokenizer: Bloodhound.tokenizers.whitespace,
prefetch: {
url: 'https://bootstrap-tagsinput.github.io/bootstrap-tagsinput/examples/assets/citynames.json',
filter: function(list) {
return $.map(list, function(cityname) {
return { name: cityname }; });
}
}
});
citynames.initialize();
$('input').tagsinput({
typeaheadjs: {
name: 'citynames',
displayKey: 'name',
valueKey: 'name',
source: citynames.ttAdapter()
}
});
html
<div class="container">
<div class="col-12-xs">
<div class="">
<input type="text" value="Amsterdam,Washington" />
</div>
</div>
</div>
CSS
.icon-github {
background: no-repeat url('../img/github-16px.png');
width: 16px;
height: 16px;
}
.bootstrap-tagsinput {
width: 100%;
}
.accordion {
margin-bottom:-3px;
}
.accordion-group {
border: none;
}
.twitter-typeahead .tt-query,
.twitter-typeahead .tt-hint {
margin-bottom: 0;
}
.twitter-typeahead .tt-hint
{
display: none;
}
.tt-menu {
position: absolute;
top: 100%;
left: 0;
z-index: 1000;
display: none;
float: left;
min-width: 160px;
padding: 5px 0;
margin: 2px 0 0;
list-style: none;
font-size: 14px;
background-color: #ffffff;
border: 1px solid #cccccc;
border: 1px solid rgba(0, 0, 0, 0.15);
border-radius: 4px;
-webkit-box-shadow: 0 6px 12px rgba(0, 0, 0, 0.175);
box-shadow: 0 6px 12px rgba(0, 0, 0, 0.175);
background-clip: padding-box;
cursor: pointer;
}
.tt-suggestion {
display: block;
padding: 3px 20px;
clear: both;
font-weight: normal;
line-height: 1.428571429;
color: #333333;
white-space: nowrap;
}
.tt-suggestion:hover,
.tt-suggestion:focus {
color: #ffffff;
text-decoration: none;
outline: 0;
background-color: #428bca;
}
Codepen
Codepen

in FF flex container affects width and height of child items

project is made on full BEM-STACK techology, so its not easy to show all code. in project's footer there's almost that following structure :
<div class="footer">
<div class="footer__inner">
<div class="footer__content page__col_8 footer__section">
</div>
<div class="footer__feedback page__col_3 footer__section ">
</div>
<div class="footer__social page__col_1 footer__section">
</div>
</div>
</div>
here are exact styles :
.footer {
height: 180px;
&__inner {
width: 1200px;
margin: 40px auto;
height: 100px;
display: flex;
padding: 0;
}
}
&__section {
box-sizing: border-box;
padding: 20px;
border: 2px solid var(--color-border);
border-right: 0px;
}
}
.page {
&__col {
&_1 {
width : 8.3333333333333%;
}
&_2 {
width : calc(2 / 12 * 100%);
}
&_3 {
width : calc(3 / 12 * 100%);
}
&_4 {
width : calc(4 / 12 * 100%);
}
&_5 {
width : calc(5 / 12 * 100%);
}
&_7 {
width : calc(7 / 12 * 100%);
}
&_8 {
width : calc(8 / 12 * 100%);
}
}
}
.footer {
&__social {
padding: 0px;
border: 1px solid var(--color-border);
width: 100px;
.link {
box-sizing: border-box;
display: inline-block;
width: 49px;
height: 49px;
border: 1px solid var(--color-border);
}
}
}
In all browsers except Firefeox width and height of .link are 49px, border is 1px. And in FF these values are computed into 48.16667px and 0.96667px. How can that be fixed? prefixes should have been added by ENB build system

MVC 3 Razor webgrid - how to change the table width

I have a problem where whatever I try I can't change the width of the webgrid table. It ignores the css of its parent div and changing the width of the grid using css doesn't have any effect.
Webgrid partial view
#model IEnumerable<UserManager.Models.vw_UserManager_Model>
#{WebGrid grid = new WebGrid(Model, canPage: true, canSort: true, rowsPerPage: 15, selectionFieldName: "selectedRow", fieldNamePrefix: "gridItem");}
<b>#Html.Label("Total number of records displayed: ")</b>
#Html.Label(grid.TotalRowCount.ToString())
#grid.GetHtml(
fillEmptyRows: true,
tableStyle: "webgrid",
alternatingRowStyle: "webgrid-alternating-row",
headerStyle: "webgrid-header",
footerStyle: "webgrid-footer",
selectedRowStyle: "webgrid-selected-row",
rowStyle: "webgrid-row-style",
mode: WebGridPagerModes.All,
columns: new[] {
grid.Column("UserName"),
grid.Column("salutation"),
grid.Column("FirstName"),
grid.Column("LastName"),
grid.Column("Password"),
grid.Column(header: "Session Status", canSort: true, format: #<text><input name="User logged in"
type="checkbox" #(item.session_status == 1 ? "Checked" : null) onclick="logUserOff('#Url.Action("LogUserOff", "UserManager", new {userid = item.userid} )')" id="chkboxIsActive" /></text>),
grid.Column("isactive"),
//grid.Column("isapproved"),
grid.Column("MaxConcurrentUsers"),
grid.Column("email"),
grid.Column("group_name"),
grid.Column("module_name"),
grid.Column(header:"Edit", format:#<text><div id="btnEditSelectedRow">
#Html.ActionLink("Edit record", "EditUser", "UserManager", new {
userid = item.userid,
salutation = item.salutation,
firstname = item.FirstName,
lastname = item.LastName,
password = item.Password,
isactive = item.isactive,
isapproved = item.IsApproved,
maxconcurrentusers = item.MaxConcurrentUsers,
email = item.email,
rowtype = item.rowtype,
module = item.module_name,
group = item.group_name }, null)</div></text>),
grid.Column(header:"Delete", format:#<text><div id="btnDelSelectedRow">
#Html.ActionLink("Delete record", "DeleteUser", "UserManager", new {
userid = item.userid,
username = item.UserName,
salutation = item.salutation,
firstname = item.FirstName,
lastname = item.LastName,
password = item.Password,
isactive = item.isactive,
email = item.email,
module = item.module_name,
rowtype = item.rowtype,
group = item.group_name }, null)</div></text>),
})
Webgrid CSS
.webgrid
{
width: 500px;
border: 0px;
border-collapse: collapse;
oveflow:scroll auto;
}
.webgrid a
{
color: #000;
}
.webgrid-header
{
padding: 6px 5px;
text-align: center;
background-color: #e8eef4;
border-bottom: 2px solid #3966A2;
height: 40px;
border-top: 2px solid #D6E8FF;
border-left: 2px solid #D6E8FF;
border-right: 2px solid #D6E8FF;
}
.webgrid-footer
{
padding: 6px 5px;
text-align: center;
background-color: #e8eef4;
border-top: 2px solid #3966A2;
height: 30px;
border-bottom: 2px solid #D6E8FF;
border-left: 2px solid #D6E8FF;
border-right: 2px solid #D6E8FF;
}
.webgrid-alternating-row
{
height: 30px;
background-color: #f2f2f2;
border-bottom: 1px solid #d2d2d2;
border-left: 2px solid #D6E8FF;
border-right: 2px solid #D6E8FF;
}
.webgrid-row-style
{
height: 30px;
border-bottom: 1px solid #d2d2d2;
border-left: 2px solid #D6E8FF;
border-right: 2px solid #D6E8FF;
}
.webgrid-selected-row
{
font-weight: bold;
}
The problem is in the .css file that Visual Studio generated. Open Content\Site.css & you will find a style definition like:
.content-wrapper {
margin: 0 auto;
max-width: 960px;
}
the max-width is too small for your table, so enlarge it. (And reload the browser b/c broswers tend to cache .css files)
Also, you can adjust the Table DataCell that has the bad wrapping by replacing with (Although, if you only adjust the w/out increasing the max width, it will force some other cell(s) to wrap)
Site.css generated by MVC3 has .page {width: 98%;} You can change that to some fixed value, like, "width: 2000px;". This helps, but if someone knows how to make it expand to the size of the WebGrid, that would be much better!

Resources