Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nimble-text-area should allow setting width #457

Merged
merged 10 commits into from
Mar 31, 2022
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "patch",
"comment": "nimble-text-area honor height and width",
"packageName": "@ni/nimble-components",
"email": "7282195+m-akinc@users.noreply.github.com",
"dependentChangeType": "patch"
}
16 changes: 14 additions & 2 deletions packages/nimble-components/src/text-area/styles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,23 @@ import { appearanceBehavior } from '../utilities/style/appearance';
import { TextAreaAppearance } from './types';

export const styles = css`
${display('inline-block')}
${display('inline-flex')}

:host {
font: ${bodyFont};
outline: none;
user-select: none;
color: ${bodyFontColor};
flex-direction: column;
vertical-align: top;
}

:host([disabled]) {
color: ${bodyDisabledFontColor};
}

.label {
display: flex;
display: block;
color: ${controlLabelFontColor};
font: ${controlLabelFont};
}
Expand All @@ -43,6 +45,8 @@ export const styles = css`
.control {
-webkit-appearance: none;
font: inherit;
width: 100%;
flex-grow: 1;
outline: none;
box-sizing: border-box;
position: relative;
Expand Down Expand Up @@ -92,6 +96,14 @@ export const styles = css`
color: ${controlLabelDisabledFontColor};
}

:host([cols]) .control {
width: auto;
}

:host([rows]) .control {
flex: none;
}

:host([resize='both']) .control {
resize: both;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,61 @@ export const textAreaThemeMatrix: Story = createRenderer(
)
);

const widthSizingTestCase = (
[widthLabel, widthStyle]: [string, string],
[colsLabel, cols]: [string, number | undefined]
): ViewTemplate => html`
<div style="width: 500px; height: 100px; outline: 1px dotted black">
<nimble-text-area
cols="${() => cols}"
style="${widthStyle}"
value="Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum."
>
${widthLabel} ${colsLabel}
</nimble-text-area>
</div>
`;

const heightSizingTestCase = (
[heightLabel, heightStyle]: [string, string],
[rowsLabel, rows]: [string, number | undefined]
): ViewTemplate => html`
<div style="width: 500px; height: 100px; outline: 1px dotted black">
<nimble-text-area
rows="${() => rows}"
style="${heightStyle}"
value="Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum."
>
${heightLabel} ${rowsLabel}
</nimble-text-area>
</div>
`;

export const textAreaSizing: Story = createRenderer(html`
${createMatrix(widthSizingTestCase, [
[
['No width', ''],
['Width=300px', 'width: 300px'],
['Width=100%', 'width: 100%']
],
[
['no cols', undefined],
['cols=10', 10]
]
])}
${createMatrix(heightSizingTestCase, [
[
['No height', ''],
['Height=50px', 'height: 50px'],
['Height=100%', 'height: 100%']
],
[
['no rows', undefined],
['rows=3', 3]
]
])}
`);

export const hiddenTextArea: Story = createRenderer(
hiddenWrapper(
html`<nimble-text-area hidden>Hidden text area</nimble-text-area>`
Expand Down