Skip to content

Disable hint #186

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

Closed
wants to merge 5 commits into from
Closed
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 CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

_(add items here for easier creation of next log entry)_

- [Feature] Add and document `displayHint` option.
- Allow space to confirm an option, fixes #98.

## 1.4.1 - 2017-07-06
Expand Down
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,12 @@ Type: `string`

Specify a string to prefill the autocomplete with.

#### `displayHint` (default: `true`)

Type: `boolean`

You can set this property to false to prevent the hint from being displayed when autoselect is on.

#### `displayMenu` (default: `'inline'`)

Type: `'inline' | 'overlay'`
Expand Down
2 changes: 1 addition & 1 deletion dist/accessible-autocomplete.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/accessible-autocomplete.min.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/lib/accessible-autocomplete.preact.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/lib/accessible-autocomplete.preact.min.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/lib/accessible-autocomplete.react.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/lib/accessible-autocomplete.react.min.js.map

Large diffs are not rendered by default.

17 changes: 17 additions & 0 deletions examples/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,11 @@ <h3><code>{ autoselect: true }</code></h3>
<label for="autocomplete-autoselect">Select your country</label>
<div id="tt-autoselect" class="autocomplete-wrapper"></div>

<h3><code>{ autoselect: true, displayHint: false }</code></h3>
<p>This option will automatically select the first suggestion without displaying a hint.</p>
<label for="autocomplete-noHint">Select your country</label>
<div id="tt-noHint" class="autocomplete-wrapper"></div>

<h3><code>{ defaultValue: 'Germany' }</code></h3>
<p>This option will prefill the input with a value.</p>
<label for="autocomplete-defaultValue">Select your country</label>
Expand Down Expand Up @@ -435,6 +440,18 @@ <h3>Custom results</h3>
})
</script>

<script type="text/javascript">
element = document.querySelector('#tt-noHint')
id = 'autocomplete-noHint'
accessibleAutocomplete({
autoselect: true,
displayHint: false,
element: element,
id: id,
source: countries
})
</script>

<script type="text/javascript">
element = document.querySelector('#tt-overlay')
id = 'autocomplete-overlay'
Expand Down
66 changes: 33 additions & 33 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 4 additions & 3 deletions src/autocomplete.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,15 @@ function onChangeCrossLibrary (handler) {
export default class Autocomplete extends Component {
static defaultProps = {
autoselect: false,
confirmOnBlur: true,
cssNamespace: 'autocomplete',
defaultValue: '',
displayHint: true,
displayMenu: 'inline',
minLength: 0,
name: 'input-autocomplete',
placeholder: '',
onConfirm: () => {},
confirmOnBlur: true,
showNoOptionsFound: true,
showAllValues: false,
required: false
Expand Down Expand Up @@ -384,7 +385,7 @@ export default class Autocomplete extends Component {
}

render () {
const { cssNamespace, displayMenu, id, minLength, name, placeholder, required, showAllValues } = this.props
const { cssNamespace, displayHint, displayMenu, id, minLength, name, placeholder, required, showAllValues } = this.props
const { focused, hovered, menuOpen, options, query, selected } = this.state
const autoselect = this.hasAutoselect()

Expand Down Expand Up @@ -418,7 +419,7 @@ export default class Autocomplete extends Component {
const hintValue = (optionBeginsWithQuery && autoselect)
? query + selectedOptionText.substr(query.length)
: ''
const showHint = hasPointerEvents && hintValue
const showHint = hasPointerEvents && hintValue && displayHint

return (
<div className={wrapperClassName} onKeyDown={this.handleKeyDown}>
Expand Down
Loading