I am getting my hands into glamorous, which is a React component styling module. I have two buttons that I am trying to style: Add
and Clear
. I am attempting to have the two buttons on the same row with the Clear
button on the left and Add
button on the right. I am having trouble making the two buttons on the same row. Instead, the Clear
button is underneath the Add
button. This is what I have:
import * as React from "react";
import glamorous from "glamorous";
import { CSSProperties } from "glamorous/typings/css-properties";
import { graphql, InjectedGraphQLProps } from "react-apollo";
import { reduxForm, Field, FormProps, WrappedFieldProps } from "redux-form";
import { ItemListQuery, AddItemMutation, AddItemMutationVariables } from "../queries/types";
const Form = glamorous.form({
display: "flex",
flexFlow: "column nowrap",
maxWidth: 320,
"> *": { margin: "1 1 30px" }
});
const Label = glamorous.label({
display: "flex",
flexFlow: "column-reverse",
"> :first-child": { marginTop: 5 }
});
const sharedInputStyles: CSSProperties = {
backgroundColor: "#e9e9e9",
border: "none",
borderBottom: "2px solid #e9e9e9",
padding: 6,
outline: "none",
transition: "all .2s ease-in",
":focus": {
borderBottom: "2px solid #777",
},
fontSize: 14,
fontWeight: 200
};
const ItemInput = glamorous.input(
sharedInputStyles,
{ height: 24 }
);
const Button = glamorous.button({
height: 40,
backgroundColor: "#bababa",
border: "none",
outline: "none",
":focus": { border: "2px solid #777" },
":active": {
backgroundColor: "#fff",
border: "2px solid #dcdcdc"
}
});
const ItemField = ({ input }: WrappedFieldProps<{}>) => (
<ItemInput {...input} />
);
export interface AddItemProps extends
InjectedGraphQLProps<{}>,
FormProps<Partial<Item>, undefined, undefined> {
}
const AddItem = ({ handleSubmit }: AddItemProps) => (
<Form onSubmit={handleSubmit}>
<Label>
Name
<Field name="name" component={ItemField} />
</Label>
<Button type="submit">Submit</Button>
<Button type="submit">Reset</Button>
</Form>
);
I tried adding display: "inline"
to the Button component like this:
const Button = glamorous.button({
height: 40,
backgroundColor: "#bababa",
display: "inline",
border: "none",
outline: "none",
":focus": { border: "2px solid #777" },
":active": {
backgroundColor: "#fff",
border: "2px solid #dcdcdc"
}
});
It did not do anything. Next, I tried changing it to display: "inline-block"
:
const Button = glamorous.button({
height: 40,
backgroundColor: "#bababa",
display: "inline-block",
border: "none",
outline: "none",
":focus": { border: "2px solid #777" },
":active": {
backgroundColor: "#fff",
border: "2px solid #dcdcdc"
}
});
Finally, I tried to add overflow: "auto"
to the Button component:
const Button = glamorous.button({
height: 40,
backgroundColor: "#bababa",
display: "inline-block",
overflow: "auto",
border: "none",
outline: "none",
":focus": { border: "2px solid #777" },
":active": {
backgroundColor: "#fff",
border: "2px solid #dcdcdc"
}
});
It did not work as well. All my attempts did not do anything to the buttons. How can I place the buttons on the same row that is evenly spaced on the form?
I know it's been a while, but maybe it will help someone:
The problem is in the
Form
element. It has style of flex column, that's why it positions its children on new lines. If you add a wrapper around buttons, even a simple div, they would behave as you expect them:Here is a slightly modified code snippet: https://stackblitz.com/edit/react-vgnjjz