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

added event keydown to prevent < or > #433

Merged
merged 24 commits into from
Sep 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
c553ca3
added event keydown to prevent < or >
wannieman98 Apr 16, 2022
3b1b7a0
added test case but still need more to verify it works throughly
wannieman98 Apr 17, 2022
3cd38f9
build package changes
wannieman98 Apr 18, 2022
0287373
added extra tests to make sure the function follows expected behavior
wannieman98 Apr 18, 2022
aaf30ea
added more documentation
wannieman98 Apr 18, 2022
f372f79
Delete 7dc7401b7c586711.txt
wannieman98 Apr 18, 2022
20de868
Delete main.d.ts
wannieman98 Apr 18, 2022
e53c01f
rollback package-lock.json to be the same as main
wannieman98 Apr 18, 2022
64813fa
rolled back tailwindcss-x file
wannieman98 Apr 18, 2022
9b9b074
rolled back package-lock.json change
wannieman98 Apr 19, 2022
d8a2d96
added prevent method using beforeinput event as well as typing but ne…
wannieman98 Apr 19, 2022
1b3bda4
use beforeInput for typing and keydown for preventing pasted query fr…
wannieman98 Apr 20, 2022
ab47378
Revert "use beforeInput for typing and keydown for preventing pasted …
wannieman98 Apr 20, 2022
1eb2c58
Update search-input.vue
wannieman98 Jun 9, 2022
0bcac5e
Update packages/x-components/src/x-modules/search-box/components/sear…
wannieman98 Jun 9, 2022
982a774
Update packages/x-components/src/x-modules/search-box/components/sear…
wannieman98 Jun 9, 2022
af586e5
deleted preventTypingSpecialKey function
wannieman98 Jun 9, 2022
d9f0891
Merge branch 'main' of https://github.com/wannieman98/x into restrict…
wannieman98 Jun 9, 2022
c6964aa
Merge branch 'empathyco:main' into restrictInput
wannieman98 Jun 9, 2022
40e504e
Merge branch 'restrictInput' of https://github.com/wannieman98/x into…
wannieman98 Jun 9, 2022
8d8bcb6
removed parcel-cache
wannieman98 Jun 9, 2022
f2a6a1f
removed the jest tests
wannieman98 Jun 9, 2022
a78990f
Merge branch 'main' into restrictInput
mnavarroespinosa Sep 20, 2022
eeb2f15
Fix build errors
mnavarroespinosa Sep 20, 2022
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
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
@input="emitUserIsTypingAQueryEvents"
@keydown.enter="emitUserPressedEnterKey"
@keydown.up.down.prevent="emitUserPressedArrowKey"
@beforeinput="preventSpecialKey"
v-on="$listeners"
:maxlength="maxLength"
:value="query"
Expand Down Expand Up @@ -90,7 +91,7 @@
/**
* When event {@link XEventsTypes.UserReachedEmpathizeTop} or
* {@link SearchBoxXEvents.UserPressedClearSearchBoxButton}
* are emitted the search in put is focused.
* are emitted the search input is focused.
wannieman98 marked this conversation as resolved.
Show resolved Hide resolved
*
* @internal
*/
Expand Down Expand Up @@ -235,6 +236,18 @@
protected emitUserAcceptedAQuery(query: string): void {
this.$x.emit('UserAcceptedAQuery', query, this.createEventMetadata());
}

/**
* Prevents the user from either typing or pasting special characters in the input field.
*
* @internal
* @param event - The event that will be checked for special characters.
*/
protected preventSpecialKey(event: InputEvent): void {
if (/[<>]/.test(event.data ?? '')) {
event.preventDefault();
}
}
}
</script>

Expand Down
50 changes: 50 additions & 0 deletions packages/x-components/tests/unit/search-input-mock.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import { mount } from '@cypress/vue';
import Vue from 'vue';
import { XPlugin } from '../../src/plugins/x-plugin';
import { BaseXBus } from '../../src/plugins/x-bus';
import { e2eAdapter } from '../../src/adapter/e2e-adapter';
import SearchInput from '../../src/x-modules/search-box/components/search-input.vue';
import { searchBoxXModule } from '../../src/x-modules/search-box';

/**
* Renders an {@link SearchInput} component with the provided options.
*
* @returns Helper methods for the rendered {@link SearchInput}.
*/
function mountSearchInput(): MountSearchInputAPI {
XPlugin.resetInstance();
mount(
{
components: {
SearchInput
},
template: `
<SearchInput />
`
},
{
vue: Vue.extend({}),
plugins: [
[new XPlugin(new BaseXBus()), { adapter: e2eAdapter, initialXModules: [searchBoxXModule] }]
]
}
);

return {
getSearchInput() {
return cy.getByDataTest('search-input');
}
};
}

describe('testing search input', () => {
it('ignores invalid typed characters', () => {
const { getSearchInput } = mountSearchInput();
getSearchInput().type('le<g>o >star>').invoke('val').should('equal', 'lego star');
});
});

interface MountSearchInputAPI {
/** Mounts search input api. */
getSearchInput: () => Cypress.Chainable<JQuery>;
}