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

Update va-select events #351

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from 5 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
13 changes: 13 additions & 0 deletions packages/storybook/stories/va-select.stories.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,18 @@ export default {
},
},
},
argTypes: {
keydown: {
description: 'Fires when a key is pressed',
table: {
category: 'Events',
defaultValue: {
detail: undefined,
},
},
type: { name: 'Event' },
},
},
};

const defaultArgs = {
Expand Down Expand Up @@ -79,6 +91,7 @@ const Template = ({
error={error}
aria-live-region-text={ariaLiveRegionText}
use-add-button={useAddButton}
onKeyDown={() => console.log('KEYDOWN FIRED')}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm also in favor of this native event + handler replacing the custom one 👍

>
{modifiedOptions}
</va-select>
Expand Down
4 changes: 0 additions & 4 deletions packages/web-components/src/components.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1114,10 +1114,6 @@ declare namespace LocalJSX {
* The event used to track usage of the component. This is emitted when an option is selected and enableAnalytics is true.
*/
"onComponent-library-analytics"?: (event: CustomEvent<any>) => void;
/**
* The event attached to select's onkeydown
*/
"onVaKeyDown"?: (event: CustomEvent<any>) => void;
/**
* The event emitted when the selected value changes
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ describe('va-select', () => {
</va-select>
`);

const keyDownSpy = await page.spyOnEvent('vaKeyDown');
const keyDownSpy = await page.spyOnEvent('keydown');

const handle = await page.$('pierce/select');
await handle.press('ArrowDown');
Expand Down
16 changes: 5 additions & 11 deletions packages/web-components/src/components/va-select/va-select.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,14 @@ export class VaSelect {
*/
@Prop() enableAnalytics: boolean;

/**
* The event attached to select's onkeydown
*/
@Event() vaKeyDown: EventEmitter;

/**
* The event emitted when the selected value changes
*/
@Event() vaSelect: EventEmitter;
@Event({
bubbles: true,
composed: true,
})
vaSelect: EventEmitter;
Comment on lines +54 to +58
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, this is what should make that test easier for the app team, right? I was too focused on the keydown changes to notice this the first time 🙃

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The tests are still failing locally when using userEvent.click(await screen.findByText(/use your current location/i));. 😞


/**
* The event used to track usage of the component. This is emitted when an
Expand All @@ -71,10 +70,6 @@ export class VaSelect {

@State() options: Array<Node>;

private handleKeyDown() {
this.vaKeyDown.emit();
}

private handleChange(e: Event) {
const target: HTMLSelectElement = e.target as HTMLSelectElement;
this.value = target.value;
Expand Down Expand Up @@ -134,7 +129,6 @@ export class VaSelect {
aria-describedby={errorSpanId}
id="select"
name={name}
onKeyDown={() => this.handleKeyDown()}
onChange={e => this.handleChange(e)}
>
{this.options}
Expand Down