Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 2 additions & 18 deletions documentation-site/examples/textarea/resizable.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,9 @@ export default function Example() {
return (
<Textarea
value={value}
onChange={e => setValue(e.currentTarget.value)}
onChange={(e) => setValue(e.currentTarget.value)}
placeholder="Try resizing me..."
overrides={{
Input: {
style: {
maxHeight: '300px',
minHeight: '100px',
minWidth: '300px',
width: '100vw', // fill all available space up to parent max-width
resize: 'both',
},
},
InputContainer: {
style: {
maxWidth: '100%',
width: 'min-content',
},
},
}}
resize="both"
/>
);
}
20 changes: 2 additions & 18 deletions documentation-site/examples/textarea/resizable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,9 @@ export default function Example() {
return (
<Textarea
value={value}
onChange={e => setValue(e.currentTarget.value)}
onChange={(e) => setValue(e.currentTarget.value)}
placeholder="Try resizing me..."
overrides={{
Input: {
style: {
maxHeight: '300px',
minHeight: '100px',
minWidth: '300px',
width: '100vw', // fill all available space up to parent max-width
resize: 'both',
},
},
InputContainer: {
style: {
maxWidth: '100%',
width: 'min-content',
},
},
}}
resize="both"
/>
);
}
1 change: 1 addition & 0 deletions src/input/__tests__/__snapshots__/utils.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ Object {
"$isReadOnly": false,
"$positive": false,
"$required": false,
"$resize": undefined,
"$size": "default",
}
`;
1 change: 1 addition & 0 deletions src/input/base-input.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,7 @@ class BaseInput<T extends HTMLInputElement | HTMLTextAreaElement> extends React.
const [Input, inputProps] = getOverrides(InputOverride, StyledInput);
const [Before, beforeProps] = getOverrides(BeforeOverride, NullComponent);
const [After, afterProps] = getOverrides(AfterOverride, NullComponent);

return (
<InputContainer
data-baseweb={this.props['data-baseweb'] || 'base-input'}
Expand Down
3 changes: 3 additions & 0 deletions src/input/types.js.flow
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ LICENSE file in the root directory of this source tree.
*/
// @flow
import * as React from 'react';
import type { Property$Resize } from 'csstype';
import type { OverrideT } from '../helpers/overrides.js';
import { STATE_CHANGE_TYPE, ADJOINED, SIZE, ENHANCER_POSITION } from './constants.js';

Expand Down Expand Up @@ -52,6 +53,7 @@ export type SharedPropsT = {|
$size: SizeT,
/** Renders UI in 'required' state */
$required: boolean,
$resize?: Property$Resize,
$position: $Keys<typeof ENHANCER_POSITION>,
/** Defines if has a clearable or MaskToggleButton at the end */
$hasIconTrailing: boolean,
Expand Down Expand Up @@ -128,6 +130,7 @@ export type BaseInputPropsT<T> = {|
placeholder?: string,
/** Renders component in 'required' state. */
required: boolean,
resize?: Property$Resize,
/** Input role attribute. */
role?: string,
/** Renders component in provided size. */
Expand Down
3 changes: 3 additions & 0 deletions src/input/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ This source code is licensed under the MIT license found in the
LICENSE file in the root directory of this source tree.
*/
import * as React from 'react';
import type { Properties } from 'csstype';
import type { Override } from '../helpers/overrides';
import { STATE_CHANGE_TYPE, ADJOINED, SIZE, ENHANCER_POSITION } from './constants';

Expand Down Expand Up @@ -48,6 +49,7 @@ export type SharedProps = {
$size: Size;
/** Renders UI in 'required' state */
$required?: boolean;
$resize?: Properties['resize'];
$position?: keyof typeof ENHANCER_POSITION;
/** Defines if has a clearable or MaskToggleButton at the end */
$hasIconTrailing?: boolean;
Expand Down Expand Up @@ -123,6 +125,7 @@ export type BaseInputProps<T> = {
placeholder?: string;
/** Renders component in 'required' state. */
required?: boolean;
resize?: Properties['resize'];
/** Input role attribute. */
role?: string;
/** Renders component in provided size. */
Expand Down
3 changes: 2 additions & 1 deletion src/input/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export function getSharedProps<T>(
props: BaseInputProps<T> | InputProps,
state: InternalState
): SharedProps {
const { disabled, error, positive, adjoined, size, required, readOnly } = props;
const { disabled, error, positive, adjoined, size, required, resize, readOnly } = props;
const { isFocused } = state;
return {
$isFocused: isFocused,
Expand All @@ -20,6 +20,7 @@ export function getSharedProps<T>(
$adjoined: adjoined,
$size: size,
$required: required,
$resize: resize,
$isReadOnly: readOnly,
};
}
19 changes: 19 additions & 0 deletions src/textarea/__tests__/textarea-resize.scenario.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/*
Copyright (c) Uber Technologies, Inc.

This source code is licensed under the MIT license found in the
LICENSE file in the root directory of this source tree.
*/
import * as React from 'react';

import { StatefulTextarea } from '..';

export function Scenario() {
return (
<StatefulTextarea
placeholder="Uncontrolled textarea"
initialState={{ value: 'initial value' }}
resize="both"
/>
);
}
2 changes: 2 additions & 0 deletions src/textarea/__tests__/textarea.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,7 @@ LICENSE file in the root directory of this source tree.
*/
import React from 'react';
import { Scenario as TextareaDefault } from './textarea.scenario';
import { Scenario as Resize } from './textarea-resize.scenario';

export const Textarea = () => <TextareaDefault />;
export const TextareaResize = () => <Resize />;
21 changes: 13 additions & 8 deletions src/textarea/styled-components.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@ export const StyledTextAreaRoot = styled<'div', SharedStyleProps>(
$theme: Theme;
}
) => {
return getRootStyles({ $positive: false, ...props, $hasIconTrailing: false });
return {
...getRootStyles({ $positive: false, ...props, $hasIconTrailing: false }),
width: props.$resize ? 'fit-content' : '100%',
};
}
);

Expand All @@ -27,9 +30,9 @@ export const StyledTextareaContainer = styled<'div', SharedStyleProps>(
props: SharedStyleProps & {
$theme: Theme;
}
) => ({
...getInputContainerStyles({ $positive: false, ...props }),
})
) => {
return getInputContainerStyles({ $positive: false, ...props });
}
);

StyledTextareaContainer.displayName = 'StyledTextareaContainer';
Expand All @@ -40,9 +43,11 @@ export const StyledTextarea = styled<'textarea', SharedStyleProps>(
props: SharedStyleProps & {
$theme: Theme;
}
) => ({
...getInputStyles(props),
resize: 'none',
})
) => {
return {
...getInputStyles(props),
resize: props.$resize || 'none',
};
}
);
StyledTextarea.displayName = 'StyledTextarea';
2 changes: 2 additions & 0 deletions src/textarea/textarea.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ class Textarea extends React.Component<
$error={this.props.error}
$positive={this.props.positive}
$required={this.props.required}
$resize={this.props.resize}
{...rootProps}
>
{/* $FlowFixMe */}
Expand All @@ -84,6 +85,7 @@ class Textarea extends React.Component<
overrides={inputOverrides}
onFocus={this.onFocus}
onBlur={this.onBlur}
resize={this.props.resize}
/>
</Root>
);
Expand Down
4 changes: 3 additions & 1 deletion src/textarea/types.js.flow
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ LICENSE file in the root directory of this source tree.
*/
// @flow
import * as React from 'react';

import type { Property$Resize } from 'csstype';
import type { OverrideT } from '../helpers/overrides.js';
import type { BaseInputPropsT, StateReducerT, StateT } from '../input/types.js';
import { ADJOINED, SIZE } from '../input/constants.js';
Expand All @@ -23,6 +23,7 @@ export type SharedStylePropsT = {
$isReadOnly: boolean,
$positive?: boolean,
$required: boolean,
$resize?: Property$Resize,
$size: SizeT,
};

Expand All @@ -36,6 +37,7 @@ export type TextareaOverridesT = {
export type TextareaPropsT = {
...BaseTextAreaPropsT,
overrides?: TextareaOverridesT,
resize?: Property$Resize,
/** Sets the size and number of visible text lines
of the textarea element. */
rows?: number,
Expand Down
4 changes: 3 additions & 1 deletion src/textarea/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ This source code is licensed under the MIT license found in the
LICENSE file in the root directory of this source tree.
*/
import * as React from 'react';

import type { Properties } from 'csstype';
import type { Override } from '../helpers/overrides';
import type { BaseInputProps, StateReducer, State } from '../input';
import { ADJOINED, SIZE } from '../input';
Expand All @@ -24,6 +24,7 @@ export type SharedStyleProps = {
$isReadOnly?: boolean;
$positive?: boolean;
$required?: boolean;
$resize?: Properties['resize'];
$size: Size;
};

Expand All @@ -35,6 +36,7 @@ export type TextareaOverrides = {

export type TextareaProps = {
overrides?: TextareaOverrides;
resize?: Properties['resize'];
/** Sets the size and number of visible text lines
of the textarea element. */
rows?: number;
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.