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

[core] feat(InputGroup): support read-only modifier #5839

Merged
merged 3 commits into from
Jan 23, 2023
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
1 change: 1 addition & 0 deletions packages/core/src/common/classes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ export const LOADING = `${NS}-loading`;
export const MINIMAL = `${NS}-minimal`;
export const OUTLINED = `${NS}-outlined`;
export const MULTILINE = `${NS}-multiline`;
export const READ_ONLY = `${NS}-read-only`;
export const ROUND = `${NS}-round`;
export const SELECTED = `${NS}-selected`;
export const SMALL = `${NS}-small`;
Expand Down
19 changes: 16 additions & 3 deletions packages/core/src/components/forms/inputGroup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ export interface IInputGroupProps
asyncControl?: boolean;

/**
* Whether the input is non-interactive.
* Whether the input is disabled.
*
* Note that `rightElement` must be disabled separately; this prop will not affect it.
*
* @default false
Expand All @@ -73,8 +74,8 @@ export interface IInputGroupProps
inputRef?: React.Ref<HTMLInputElement>;

/**
* Element to render on the left side of input. This prop is mutually exclusive
* with `leftIcon`.
* Element to render on the left side of input.
* This prop is mutually exclusive with `leftIcon`.
*/
leftElement?: JSX.Element;

Expand All @@ -94,6 +95,16 @@ export interface IInputGroupProps
/** Placeholder text in the absence of any value. */
placeholder?: string;

/**
* Whether the input is read-only.
*
* Note that `rightElement` must be disabled or made read-only separately;
* this prop will not affect it.
*
* @default false
*/
readOnly?: boolean;

/**
* Element to render on right side of input.
* For best results, use a minimal button, tag, or small spinner.
Expand Down Expand Up @@ -184,6 +195,7 @@ export class InputGroup extends AbstractPureComponent2<InputGroupProps2, IInputG
inputRef,
intent,
large,
readOnly,
round,
small,
tagName = "div",
Expand All @@ -193,6 +205,7 @@ export class InputGroup extends AbstractPureComponent2<InputGroupProps2, IInputG
Classes.intentClass(intent),
{
[Classes.DISABLED]: disabled,
[Classes.READ_ONLY]: readOnly,
[Classes.FILL]: fill,
[Classes.LARGE]: large,
[Classes.SMALL]: small,
Expand Down
13 changes: 11 additions & 2 deletions packages/docs-app/src/examples/core-examples/inputGroupExample.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import { Popover2, Tooltip2 } from "@blueprintjs/popover2";

export interface IInputGroupExampleState {
disabled: boolean;
readOnly: boolean;
filterValue: string;
large: boolean;
small: boolean;
Expand All @@ -46,13 +47,16 @@ export class InputGroupExample extends React.PureComponent<ExampleProps, IInputG
disabled: false,
filterValue: "",
large: false,
readOnly: false,
showPassword: false,
small: false,
tagValue: "",
};

private handleDisabledChange = handleBooleanChange(disabled => this.setState({ disabled }));

private handleReadOnlyChange = handleBooleanChange(readOnly => this.setState({ readOnly }));

private handleLargeChange = handleBooleanChange(large => this.setState({ large, ...(large && { small: false }) }));

private handleSmallChange = handleBooleanChange(small => this.setState({ small, ...(small && { large: false }) }));
Expand All @@ -64,7 +68,7 @@ export class InputGroupExample extends React.PureComponent<ExampleProps, IInputG
private handleTagChange = handleStringChange(tagValue => this.setState({ tagValue }));

public render() {
const { disabled, filterValue, large, small, showPassword, tagValue } = this.state;
const { disabled, filterValue, large, readOnly, small, showPassword, tagValue } = this.state;

const maybeSpinner = filterValue ? <Spinner size={IconSize.STANDARD} /> : undefined;

Expand Down Expand Up @@ -109,6 +113,7 @@ export class InputGroupExample extends React.PureComponent<ExampleProps, IInputG
leftIcon="filter"
onChange={this.handleFilterChange}
placeholder="Filter histogram..."
readOnly={readOnly}
rightElement={maybeSpinner}
small={small}
value={filterValue}
Expand All @@ -118,6 +123,7 @@ export class InputGroupExample extends React.PureComponent<ExampleProps, IInputG
disabled={disabled}
large={large}
placeholder="Enter your password..."
readOnly={readOnly}
rightElement={lockButton}
small={small}
type={showPassword ? "text" : "password"}
Expand All @@ -128,6 +134,7 @@ export class InputGroupExample extends React.PureComponent<ExampleProps, IInputG
leftElement={<Icon icon="tag" />}
onChange={this.handleTagChange}
placeholder="Find tags"
readOnly={readOnly}
rightElement={resultsTag}
small={small}
value={tagValue}
Expand All @@ -136,6 +143,7 @@ export class InputGroupExample extends React.PureComponent<ExampleProps, IInputG
disabled={disabled}
large={large}
placeholder="Add people or groups..."
readOnly={readOnly}
rightElement={permissionsMenu}
small={small}
/>
Expand All @@ -144,11 +152,12 @@ export class InputGroupExample extends React.PureComponent<ExampleProps, IInputG
}

private renderOptions() {
const { disabled, large, small } = this.state;
const { disabled, readOnly, large, small } = this.state;
return (
<>
<H5>Props</H5>
<Switch label="Disabled" onChange={this.handleDisabledChange} checked={disabled} />
<Switch label="Read-only" onChange={this.handleReadOnlyChange} checked={readOnly} />
<Switch label="Large" onChange={this.handleLargeChange} checked={large} />
<Switch label="Small" onChange={this.handleSmallChange} checked={small} />
</>
Expand Down