diff --git a/src/__tests__/useMatches.test.tsx b/src/__tests__/useMatches.test.tsx
index 49070be..845e5d2 100644
--- a/src/__tests__/useMatches.test.tsx
+++ b/src/__tests__/useMatches.test.tsx
@@ -89,6 +89,25 @@ function WithPriorityComponent() {
);
}
+function WithLongNamesComponent() {
+ const action1 = createAction({
+ name: "Action: This is a long name ending by toto",
+ });
+ const action2 = createAction({
+ name: "Action: This is a long name also ending by toto",
+ });
+ const action3 = createAction({
+ name: "Action: This is a long name ending by titi",
+ });
+
+ return (
+
+
+
+
+ );
+}
+
const setup = (Component: React.ComponentType) => {
const utils = render();
const input = utils.getByLabelText("search-input");
@@ -143,4 +162,23 @@ describe("useMatches", () => {
expect(utils.queryAllByText(/Section 1/i));
});
});
+ describe("With long names", () => {
+ let utils: Utils;
+ beforeEach(() => {
+ utils = setup(WithLongNamesComponent);
+ });
+
+ it("returns result matching the query even if match is on a word far in the name", () => {
+ const { input } = utils;
+ fireEvent.change(input, { target: { value: "toto" } });
+ const results = utils.getAllByText(/Action/i);
+ expect(results.length).toEqual(2);
+ expect(results[0].textContent).toEqual(
+ "Action: This is a long name ending by toto"
+ );
+ expect(results[1].textContent).toEqual(
+ "Action: This is a long name also ending by toto"
+ );
+ });
+ });
});
diff --git a/src/useMatches.tsx b/src/useMatches.tsx
index 595fc86..b666437 100644
--- a/src/useMatches.tsx
+++ b/src/useMatches.tsx
@@ -22,6 +22,7 @@ const fuseOptions: Fuse.IFuseOptions = {
},
"subtitle",
],
+ ignoreLocation: true,
includeScore: true,
includeMatches: true,
threshold: 0.2,