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

[NumericInput] new rightElement prop #3314

Merged
merged 1 commit into from
Jan 23, 2019
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
16 changes: 11 additions & 5 deletions packages/core/src/components/forms/numericInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,6 @@ export interface INumericInputProps extends IIntentProps, IProps {
*/
leftIcon?: IconName | MaybeElement;

/** The placeholder text in the absence of any value. */
placeholder?: string;

/**
* The increment between successive values when <kbd>shift</kbd> is held.
* Pass explicit `null` value to disable this interaction.
Expand All @@ -108,6 +105,15 @@ export interface INumericInputProps extends IIntentProps, IProps {
*/
minorStepSize?: number | null;

/** The placeholder text in the absence of any value. */
placeholder?: string;

/**
* Element to render on right side of input.
* For best results, use a minimal button, tag, or small spinner.
*/
rightElement?: JSX.Element;

/**
* Whether the entire text field should be selected on focus.
* @default false
Expand Down Expand Up @@ -147,12 +153,11 @@ enum IncrementDirection {
UP = +1,
}

const NON_HTML_PROPS = [
const NON_HTML_PROPS: Array<keyof INumericInputProps> = [
"allowNumericCharactersOnly",
"buttonPosition",
"clampValueOnBlur",
"className",
"large",
"majorStepSize",
"minorStepSize",
"onButtonClick",
Expand Down Expand Up @@ -301,6 +306,7 @@ export class NumericInput extends AbstractPureComponent<HTMLInputProps & INumeri
onKeyDown={this.handleInputKeyDown}
onKeyPress={this.handleInputKeyPress}
onPaste={this.handleInputPaste}
rightElement={this.props.rightElement}
value={this.state.value}
/>
);
Expand Down
12 changes: 8 additions & 4 deletions packages/core/test/controls/numericInputTests.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -820,10 +820,9 @@ describe("<NumericInput>", () => {
});

it("shows a left icon if provided", () => {
const leftIcon = mount(<NumericInput leftIcon="variable" />)
.find(Icon)
.first();
expect(leftIcon.text()).to.equal("variable");
const component = mount(<NumericInput leftIcon="variable" />);
const icon = component.find(InputGroup).find(Icon);
expect(icon.prop("icon")).to.equal("variable");
});

it("shows placeholder text if provided", () => {
Expand All @@ -835,6 +834,11 @@ describe("<NumericInput>", () => {
expect(placeholderText).to.equal("Enter a number...");
});

it("shows right element if provided", () => {
const component = mount(<NumericInput rightElement={<Button />} />);
expect(component.find(InputGroup).find(Button)).to.exist;
});

it("changes max precision of displayed value to that of the smallest step size defined", () => {
const component = mount(<NumericInput majorStepSize={1} stepSize={0.1} minorStepSize={0.001} />);
const incrementButton = component.find(Button).first();
Expand Down