这是indexloc提供的服务,不要输入任何密码
Skip to content
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
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@

# React Autosuggest

## Ricardo Fork
This project has been forked to be able to render a custom wrapper for each section of the autocomplete (this is done in **react-autowhatever** that has also been forked)

## Demo

Check out the [Homepage](http://react-autosuggest.js.org) and the [Codepen examples](http://codepen.io/collection/DkkYaQ).
Expand Down Expand Up @@ -166,6 +169,7 @@ class Example extends React.Component {
| [`renderSectionTitle`](#render-section-title-prop) | Function | ✓<br>when `multiSection={true}` | Use your imagination to define how section titles are rendered. |
| [`getSectionSuggestions`](#get-section-suggestions-prop) | Function | ✓<br>when `multiSection={true}` | Implement it to teach Autosuggest where to find the suggestions for every section. |
| [`renderInputComponent`](#render-input-component-prop) | Function | | Use it only if you need to customize the rendering of the input. |
| [`renderSectionContainer`](#render-section-container-prop) | Function | | Use it only if you need to customize the rendering of the sections. |
| [`renderSuggestionsContainer`](#render-suggestions-container-prop) | Function | | Use it if you want to customize things inside the suggestions container beyond rendering the suggestions themselves. |
| [`theme`](#theme-prop) | Object | | Use your imagination to style the Autosuggest. |
| [`id`](#id-prop) | String | | Use it only if you have multiple Autosuggest components on a page. |
Expand Down Expand Up @@ -500,6 +504,18 @@ const renderInputComponent = inputProps => (

**Note:** When using `renderInputComponent`, you still need to specify the usual [`inputProps`](#input-props-prop). Autosuggest will merge the `inputProps` that you provide with other props that are needed for accessibility (e.g. `'aria-activedescendant'`), and will pass the **merged `inputProps`** to `renderInputComponent`.


<a name="render-section-container-prop"></a>
#### Added by Ricardo – renderSectionContainer (optional)

You shouldn't specify `renderSectionContainer` unless you want to customize the rendering of the sections.

The signature is:

```js
function renderSectionContainer(section, children)
```

<a name="render-suggestions-container-prop"></a>
#### renderSuggestionsContainer (optional)

Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "react-autosuggest",
"version": "9.4.3",
"name": "ricardo-react-autosuggest",
"version": "9.4.5",
"description": "WAI-ARIA compliant React autosuggest component",
"main": "dist/index.js",
"repository": {
Expand All @@ -26,7 +26,7 @@
},
"dependencies": {
"prop-types": "^15.5.10",
"react-autowhatever": "^10.1.2",
"ricardo-react-autowhatever": "^10.2.2",
"shallow-equal": "^1.0.0"
},
"peerDependencies": {
Expand Down
5 changes: 4 additions & 1 deletion src/Autosuggest.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React, { Component } from 'react';
import PropTypes from 'prop-types';
import shallowEqualArrays from 'shallow-equal/arrays';
import Autowhatever from 'react-autowhatever';
import Autowhatever from 'ricardo-react-autowhatever';
import { defaultTheme, mapToAutowhateverTheme } from './theme';

const alwaysTrue = () => true;
Expand Down Expand Up @@ -38,6 +38,7 @@ export default class Autosuggest extends Component {
onSuggestionHighlighted: PropTypes.func,
renderInputComponent: PropTypes.func,
renderSuggestionsContainer: PropTypes.func,
renderSectionContainer: PropTypes.func,
getSuggestionValue: PropTypes.func.isRequired,
renderSuggestion: PropTypes.func.isRequired,
inputProps: (props, propName) => {
Expand Down Expand Up @@ -510,6 +511,7 @@ export default class Autosuggest extends Component {
inputProps,
multiSection,
renderSectionTitle,
renderSectionContainer,
id,
getSectionSuggestions,
theme,
Expand Down Expand Up @@ -748,6 +750,7 @@ export default class Autosuggest extends Component {
renderItem={renderSuggestion}
renderItemData={renderSuggestionData}
renderSectionTitle={renderSectionTitle}
renderSectionContainer={renderSectionContainer}
getSectionItems={getSectionSuggestions}
highlightedSectionIndex={highlightedSectionIndex}
highlightedItemIndex={highlightedSuggestionIndex}
Expand Down
19 changes: 9 additions & 10 deletions test/focus-first-suggestion/AutosuggestApp.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,16 +128,15 @@ describe('Autosuggest with highlightFirstSuggestion={true}', () => {
onSuggestionSelected.reset();
clickEnter();
expect(onSuggestionSelected).to.have.been.calledOnce;
expect(onSuggestionSelected).to.have.been.calledWithExactly(
syntheticEventMatcher,
{
suggestion: { name: 'Perl', year: 1987 },
suggestionValue: 'Perl',
suggestionIndex: 0,
sectionIndex: null,
method: 'enter'
}
);
expect(
onSuggestionSelected
).to.have.been.calledWithExactly(syntheticEventMatcher, {
suggestion: { name: 'Perl', year: 1987 },
suggestionValue: 'Perl',
suggestionIndex: 0,
sectionIndex: null,
method: 'enter'
});
});
});

Expand Down
12 changes: 5 additions & 7 deletions test/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,13 +92,11 @@ export const getSuggestion = suggestionIndex => {
throw Error(
`
Cannot find suggestion #${suggestionIndex}.
${
suggestions.length === 0
? 'No suggestions found.'
: `Only ${suggestions.length} suggestion${
suggestions.length === 1 ? '' : 's'
} found.`
}
${suggestions.length === 0
? 'No suggestions found.'
: `Only ${suggestions.length} suggestion${suggestions.length === 1
? ''
: 's'} found.`}
`
);
}
Expand Down
38 changes: 18 additions & 20 deletions test/plain-list/AutosuggestApp.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -602,32 +602,30 @@ describe('Default Autosuggest', () => {
it('should be called once with the right parameters when suggestion is clicked', () => {
clickSuggestion(1);
expect(onSuggestionSelected).to.have.been.calledOnce;
expect(onSuggestionSelected).to.have.been.calledWithExactly(
syntheticEventMatcher,
{
suggestion: { name: 'JavaScript', year: 1995 },
suggestionValue: 'JavaScript',
suggestionIndex: 1,
sectionIndex: null,
method: 'click'
}
);
expect(
onSuggestionSelected
).to.have.been.calledWithExactly(syntheticEventMatcher, {
suggestion: { name: 'JavaScript', year: 1995 },
suggestionValue: 'JavaScript',
suggestionIndex: 1,
sectionIndex: null,
method: 'click'
});
});

it('should be called once with the right parameters when Enter is pressed and suggestion is highlighted', () => {
clickDown();
clickEnter();
expect(onSuggestionSelected).to.have.been.calledOnce;
expect(onSuggestionSelected).to.have.been.calledWithExactly(
syntheticEventMatcher,
{
suggestion: { name: 'Java', year: 1995 },
suggestionValue: 'Java',
suggestionIndex: 0,
sectionIndex: null,
method: 'enter'
}
);
expect(
onSuggestionSelected
).to.have.been.calledWithExactly(syntheticEventMatcher, {
suggestion: { name: 'Java', year: 1995 },
suggestionValue: 'Java',
suggestionIndex: 0,
sectionIndex: null,
method: 'enter'
});
});

it('should not be called when Enter is pressed and there is no highlighted suggestion', () => {
Expand Down