Terra-core: Do not allow user to clear selection in terra-form-select

Created on 27 Jan 2018  路  9Comments  路  Source: cerner/terra-core

Issue Description

The new terra-form-select always includes a "-Select-" option that lets the user clear the selection. We need a way for a consumer of the control to turn off this functionality, as it allows the user to leave a valid state and go to an invalid state.
(This was possible in the old terra-form/select.)

Issue Type

  • [ ] New Feature
  • [X] Enhancement
  • [ ] Bug
  • [ ] Other

Expected Behavior

Allow the consumer of terra-form-select to indicate that the user is not allowed to clear a selection once it has been set/made.

Current Behavior

The terra-form-select control always includes a "-Select-" option that lets the user clear the selection.

terra-form-select

Most helpful comment

How about isPlaceholderHidden?

All 9 comments

It might make sense to allow the - Select - option to be removed or set as a different value, etc. Here's an example of how we'd like to use it. We default to "All" so including a Select option doesn't make much sense.

screen shot 2018-02-01 at 6 50 51 pm

Tech Design

Summary

The Select component will now receive a new prop 'isPlaceholderHidden'. This prop will determine if the clear option- Select - should be visible.

React Props:

Select

Prop | Type | Default | Description
------------ | ------------- | ------------ | -------------
isPlaceholderHidden | boolean | false | Indicates whether the clear option should be visible

Examples

import React from 'react';
import Select from 'terra-form-select';

<Select
  name="foo"
  defaultValue="b"
  isPlaceholderHidden
>
  <Select.Option value="m" display="moo" key="m" />
  <Select.Option value="b" display="boo" key="b" disabled />
  <Select.Option value="z" display="zar" key="z" />
</Select>

In case when isInvalid and isPlaceholderHidden both are true for the Select component, then the default option will be a blank option.

+1 on tech design. I wish I could think of a better name for the isClearSelectionHidden prop.

Maybe some variation of:
isPlaceholderDisabled, allowBlankSelection, isNullValueDisabled, allowInvalidSelection, removeNullValue, isNullValueHidden, isDefaultValueHidden

@bjankord @dkasper-was-taken changed the prop to isPlaceholderDisabled

How about isPlaceholderHidden?

+1

Resolved in #1229

JIRA created

Was this page helpful?
0 / 5 - 0 ratings