Skip to content

Commit e0022eb

Browse files
authored
Merge pull request #31 from labd/testing
chore: remove wrapper div and clean up testing
2 parents 9bc3fe4 + dfca785 commit e0022eb

File tree

8 files changed

+558
-602
lines changed

8 files changed

+558
-602
lines changed

.changeset/wild-mangos-sleep.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
"react-loqate": major
3+
---
4+
5+
- BREAKING: remove wrapping div and the corresponding `className` input
6+
- BREAKING: custom input components now need to accept a (forwarded) ref
7+
- updated and expanded tests
8+
- updated readme

README.md

Lines changed: 17 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import 'react-loqate/dist/index.css';
2727
apiKey="AA11-AA11-AA11-AA11"
2828
onSelect={(address) => console.log(address)}
2929
/>;
30+
// ...
3031
```
3132

3233
### Props
@@ -38,46 +39,40 @@ import 'react-loqate/dist/index.css';
3839
| onSelect | (address) => void | yes | address => console.log(address) | Callback with for Loqate response |
3940
| countries | string[] | no | ["GB", "NL"] | Countries to search in |
4041
| limit | number | no | 10 | Number of options to show |
41-
| className | string | no | "address-search-box" | Classname for the component wrapper |
4242
| classes | `{ input?: string, list?: string, listItem?: string}` | no | { list: 'list' } | Classnames for the components |
4343
| components | see [Customization](#Customization) | no | { Input: CustomInput, List: CustomList, ListItem: CustomListItem, } | Components to overwrite the default ones |
4444
| inline | boolean | no | true | Render results inline with the input |
4545
| debounce | number | no | 100 | Debounce the calls to the Loqate API |
4646

4747
### Customization
4848

49-
You can either style the default input, list and listItem with their respective classes or replace them completely by passing in your own components in the components prop.
49+
You can either style the default input, list and listitem with their respective classes or replace them completely by passing in your own components in the components prop.
5050

51-
**List component must be able to accept a ref!**
51+
**Input and List components must be able to accept a ref, either through using forwardRef or being a base html element**
5252

5353
**All custom components must pass down their props!**
5454

5555
```javascript
5656
import React from 'react';
5757
import AddressSearch from 'react-loqate';
5858

59-
const CustomInput = (props): JSX.Element => {
60-
return (
61-
<input
62-
placeholder={'start typing your address or postcode'}
63-
autocomplete="chrome-off"
64-
{...props}
65-
/>
66-
);
67-
};
68-
6959
<AddressSearch
70-
locale="en-GB"
71-
apiKey="AA11-AA11-AA11-AA11"
72-
countries={['GB']}
60+
// ...
7361
components={{
74-
Input: CustomInput,
62+
Input: (props) => <input {...props} />,
63+
List: forwardRef((props, ref) => {
64+
const { className, ...rest } = props;
65+
// ..
66+
return (
67+
<ul
68+
className={clsx('react-loqate-default-list', className)}
69+
ref={ref}
70+
{...rest}
71+
/>
72+
);
73+
}),
7574
}}
76-
className="address-search-box"
77-
classes={{ list: 'styled-list' }}
78-
onSelect={(address) => console.log(address)}
79-
inline
80-
debounce={100}
75+
classes={{ listItem: 'styled-list-item' }}
8176
/>;
8277
```
8378

0 commit comments

Comments
 (0)