Skip to content

Commit

Permalink
fix: button fixes (#249)
Browse files Browse the repository at this point in the history
  • Loading branch information
aotearoan authored Dec 26, 2024
1 parent c7ad618 commit 57880bb
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 2 deletions.
6 changes: 6 additions & 0 deletions src/app/views/user-input/button/Button.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,11 @@ export default defineComponent({
<neon-button target="_blank" href="/" label="Link button" />
<neon-button :full-width="true" button-style="outline" label="Full width button" />`;

const responsiveExample = `<div class="neon-button-group">
<neon-button button-style="text" color="primary" label="Cancel"/>
<neon-button color="primary" label="Accept"/>
</div>`;

const withIconExamples = `<neon-button icon="plus" label="With icon" />
<neon-button icon="plus" icon-position="right" label="Positioned right" />`;

Expand Down Expand Up @@ -98,6 +103,7 @@ export default defineComponent({
functionalColorExamples,
gradientExamples,
styleExamples,
responsiveExample,
withIconExamples,
iconOnlyExamples,
stateExamples,
Expand Down
16 changes: 16 additions & 0 deletions src/app/views/user-input/button/Button.vue
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,22 @@
<editor v-model="styleExamples" />
</neon-stack>
</neon-card-body>
<neon-card-body>
<h2 class="neon-h3">Responsive buttons</h2>
<neon-stack>
<neon-note color="info">
<span
>Use the <em>neon-button-group</em> class to wrap a group of buttons to make them responsive. On mobile
they will switch to a reverse column layout & become full width.</span
>
</neon-note>
<div class="neon-button-group">
<neon-button button-style="text" color="primary" label="Cancel" />
<neon-button color="primary" label="Accept" />
</div>
<editor v-model="responsiveExample" />
</neon-stack>
</neon-card-body>
<neon-card-body>
<h2 class="neon-h3">Buttons with icons</h2>
<neon-stack>
Expand Down
7 changes: 7 additions & 0 deletions src/components/user-input/button/NeonButton.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,13 @@ describe('NeonButton', () => {
expect(emitted().click).toBeDefined();
});

it('does not emit click event when disabled', async () => {
const { getByText, emitted, rerender } = harness;
await rerender({ disabled: true });
await fireEvent.click(getByText(label));
expect(emitted().click).toBeUndefined();
});

it('blurs element on click', async () => {
const { getByText } = harness;
const button = getByText(label).parentElement as HTMLButtonElement;
Expand Down
7 changes: 5 additions & 2 deletions src/components/user-input/button/NeonButton.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,12 +139,15 @@ export default defineComponent({
const clickLink = () => button.value?.click();

const sanitizedAttributes = computed(() => {
const { _onClick, ...sanitized } = attrs;
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const { onClick, ...sanitized } = attrs;
return sanitized;
});

const clickButton = () => {
emit('click');
if (!props.disabled) {
emit('click');
}
button.value?.blur();
};

Expand Down
13 changes: 13 additions & 0 deletions src/sass/components/_button.scss
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,10 @@
}
}

@mixin neon-full-width-button {
@include neon-full-width-button;
}

@mixin button {
.neon-button {
margin-left: 0;
Expand Down Expand Up @@ -384,5 +388,14 @@
justify-content: flex-end;
align-items: center;
gap: var(--neon-space-16);

@include responsive.responsive(mobile-large) {
flex-direction: column-reverse;
gap: calc(3 * var(--neon-base-space));

& > .neon-button {
@include neon-full-width-button;
}
}
}
}

0 comments on commit 57880bb

Please sign in to comment.