Skip to content
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

fix: stop touchstart event propagation if coming from cancel button in detached mode #924

Merged
merged 12 commits into from
Mar 31, 2022
2 changes: 1 addition & 1 deletion bundlesize.config.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"files": [
{
"path": "packages/autocomplete-core/dist/umd/index.production.js",
"maxSize": "6 kB"
"maxSize": "6.25 kB"
},
{
"path": "packages/autocomplete-js/dist/umd/index.production.js",
Expand Down
10 changes: 8 additions & 2 deletions packages/autocomplete-core/src/getPropGetters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,13 @@ export function getPropGetters<
TKeyboardEvent
>({ props, refresh, store, ...setters }: GetPropGettersOptions<TItem>) {
const getEnvironmentProps: GetEnvironmentProps = (providedProps) => {
const { inputElement, formElement, panelElement, ...rest } = providedProps;
const {
inputElement,
formElement,
panelElement,
isDetached,
...rest
} = providedProps;

return {
// On touch devices, we do not rely on the native `blur` event of the
Expand Down Expand Up @@ -60,7 +66,7 @@ export function getPropGetters<
);

if (isTargetWithinAutocomplete === false) {
store.dispatch('blur', null);
store.dispatch('blur', { isDetached });

// If requests are still pending when the user closes the panel, they
// could reopen the panel once they resolve.
Expand Down
2 changes: 1 addition & 1 deletion packages/autocomplete-core/src/stateReducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ export const stateReducer: Reducer = (state, action) => {
}

case 'blur': {
if (action.props.debug) {
if (action.props.debug || action.payload?.isDetached) {
return state;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export type GetEnvironmentProps = (props: {
formElement: HTMLElement;
inputElement: HTMLInputElement;
panelElement: HTMLElement;
isDetached: boolean;
}) => {
onTouchStart(event: TouchEvent): void;
onTouchMove(event: TouchEvent): void;
Expand Down
1 change: 1 addition & 0 deletions packages/autocomplete-js/src/autocomplete.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ export function autocomplete<TItem extends BaseItem>(
formElement: dom.value.form,
panelElement: dom.value.panel,
inputElement: dom.value.input,
isDetached: isDetached.value,
dhayab marked this conversation as resolved.
Show resolved Hide resolved
});

setProperties(props.value.core.environment as any, environmentProps);
Expand Down