Skip to content

Commit

Permalink
Handle custom input size with CSS to fix different behaviour across b…
Browse files Browse the repository at this point in the history
…rowsers (#101)
  • Loading branch information
adamkudrna committed Jun 12, 2020
1 parent eb3a800 commit 0f160f9
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ exports[`rendering renders correctly 1`] = `
rootVariantOutline"
htmlFor="resetEmailInput"
id="resetEmailInput__label"
style={Object {}}
>
<div
className="label"
Expand Down Expand Up @@ -224,6 +225,7 @@ exports[`rendering renders correctly 2`] = `
rootVariantOutline"
htmlFor="resetEmailInput"
id="resetEmailInput__label"
style={Object {}}
>
<div
className="label"
Expand Down Expand Up @@ -404,6 +406,7 @@ exports[`rendering renders correctly with all props except translations 1`] = `
rootVariantOutline"
htmlFor="custom-id__resetEmailInput"
id="custom-id__resetEmailInput__label"
style={Object {}}
>
<div
className="label"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ exports[`rendering renders correctly 1`] = `
rootVariantOutline"
htmlFor="usernameInput"
id="usernameInput__label"
style={Object {}}
>
<div
className="label"
Expand Down Expand Up @@ -140,6 +141,7 @@ exports[`rendering renders correctly 1`] = `
rootVariantOutline"
htmlFor="passwordInput"
id="passwordInput__label"
style={Object {}}
>
<div
className="label"
Expand Down Expand Up @@ -321,6 +323,7 @@ exports[`rendering renders correctly with all props except translations 1`] = `
rootVariantOutline"
htmlFor="custom-id__usernameInput"
id="custom-id__usernameInput__label"
style={Object {}}
>
<div
className="label"
Expand Down Expand Up @@ -387,6 +390,7 @@ exports[`rendering renders correctly with all props except translations 1`] = `
rootVariantOutline"
htmlFor="custom-id__passwordInput"
id="custom-id__passwordInput__label"
style={Object {}}
>
<div
className="label"
Expand Down Expand Up @@ -557,6 +561,7 @@ exports[`rendering renders correctly with translations 1`] = `
rootVariantOutline"
htmlFor="usernameInput"
id="usernameInput__label"
style={Object {}}
>
<div
className="label"
Expand Down Expand Up @@ -623,6 +628,7 @@ exports[`rendering renders correctly with translations 1`] = `
rootVariantOutline"
htmlFor="passwordInput"
id="passwordInput__label"
style={Object {}}
>
<div
className="label"
Expand Down Expand Up @@ -773,6 +779,7 @@ exports[`rendering renders correctly with username 1`] = `
rootVariantOutline"
htmlFor="usernameInput"
id="usernameInput__label"
style={Object {}}
>
<div
className="label"
Expand Down Expand Up @@ -839,6 +846,7 @@ exports[`rendering renders correctly with username 1`] = `
rootVariantOutline"
htmlFor="passwordInput"
id="passwordInput__label"
style={Object {}}
>
<div
className="label"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ exports[`rendering renders correctly 1`] = `
rootVariantOutline"
htmlFor="newPasswordInput"
id="newPasswordInput__label"
style={Object {}}
>
<div
className="label"
Expand Down Expand Up @@ -138,6 +139,7 @@ exports[`rendering renders correctly 1`] = `
rootVariantOutline"
htmlFor="newPasswordRepeatInput"
id="newPasswordRepeatInput__label"
style={Object {}}
>
<div
className="label"
Expand Down Expand Up @@ -317,6 +319,7 @@ exports[`rendering renders correctly with all props except translations 1`] = `
rootVariantOutline"
htmlFor="custom-id__newPasswordInput"
id="custom-id__newPasswordInput__label"
style={Object {}}
>
<div
className="label"
Expand Down Expand Up @@ -383,6 +386,7 @@ exports[`rendering renders correctly with all props except translations 1`] = `
rootVariantOutline"
htmlFor="custom-id__newPasswordRepeatInput"
id="custom-id__newPasswordRepeatInput__label"
style={Object {}}
>
<div
className="label"
Expand Down Expand Up @@ -550,6 +554,7 @@ exports[`rendering renders correctly with translations 1`] = `
rootVariantOutline"
htmlFor="newPasswordInput"
id="newPasswordInput__label"
style={Object {}}
>
<div
className="label"
Expand Down Expand Up @@ -616,6 +621,7 @@ exports[`rendering renders correctly with translations 1`] = `
rootVariantOutline"
htmlFor="newPasswordRepeatInput"
id="newPasswordRepeatInput__label"
style={Object {}}
>
<div
className="label"
Expand Down
11 changes: 11 additions & 0 deletions src/lib/components/ui/TextField/TextField.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,16 @@ export const TextField = (props) => {
rootVariantClass = styles.rootVariantOutline;
}

const inlineStyle = (inputSize) => {
const style = {};

if (inputSize) {
style['--rui-custom-input-size'] = inputSize;
}

return style;
};

const propsToTransfer = transferProps(
props,
['changeHandler', 'disabled', 'fullWidth', 'helperText', 'id', 'inFormLayout', 'inputSize', 'isLabelVisible',
Expand All @@ -86,6 +96,7 @@ export const TextField = (props) => {
`).trim()}
htmlFor={props.id}
id={`${props.id}__label`}
style={inlineStyle(props.inputSize)}
>
<div
className={(`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ exports[`rendering renders correctly mandatory props only 1`] = `
rootVariantOutline"
htmlFor="test"
id="test__label"
style={Object {}}
>
<div
className="label"
Expand Down Expand Up @@ -50,6 +51,11 @@ exports[`rendering renders correctly with all props 1`] = `
rootVariantFilled"
htmlFor="test"
id="test__label"
style={
Object {
"--rui-custom-input-size": 3,
}
}
>
<div
className="label
Expand Down Expand Up @@ -98,6 +104,7 @@ exports[`rendering renders correctly with hidden label 1`] = `
rootVariantOutline"
htmlFor="test"
id="test__label"
style={Object {}}
>
<div
className="label
Expand Down
11 changes: 9 additions & 2 deletions src/lib/styles/tools/forms/_foundation.scss
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// 1. Get ready for positioning of bottom line and caret.
// 2. Override hover style of disabled input.
// 3. Always prefer the `size` attribute when defined.
// 3. Always prefer the `size` attribute when defined. Use CSS for sizing to normalize resulting
// width across browsers.
// 4. Let inputs properly fit various layout scenarios.
// 5. Leave out space for Select Field caret.

Expand Down Expand Up @@ -67,7 +68,13 @@

@mixin form-field-input-text() {
&[size] {
width: auto; // 3.
width:
calc(
1ch * var(--rui-custom-input-size)
+ 2 * var(--rui-local-padding-horizontal)
+ 2 * #{$form-field-border-width}
); // 3.

min-width: auto; // 3.
}
}
Expand Down

0 comments on commit 0f160f9

Please sign in to comment.