Skip to content

Commit

Permalink
feat: sets action-menu quiet to false by default, fixes #3040
Browse files Browse the repository at this point in the history
  • Loading branch information
benjamind committed Mar 17, 2023
1 parent f6a7ece commit 001e71c
Show file tree
Hide file tree
Showing 9 changed files with 52 additions and 17 deletions.
3 changes: 1 addition & 2 deletions packages/action-menu/src/ActionMenu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ export class ActionMenu extends ObserveSlotText(PickerBase, 'label') {
protected override render(): TemplateResult {
return html`
<sp-action-button
quiet
?quiet=${this.quiet}
?selected=${this.open}
aria-haspopup="true"
aria-controls="popover"
Expand All @@ -85,7 +85,6 @@ export class ActionMenu extends ObserveSlotText(PickerBase, 'label') {
if (changedProperties.has('invalid')) {
this.invalid = false;
}
this.quiet = true;
super.update(changedProperties);
}
}
19 changes: 19 additions & 0 deletions packages/action-menu/stories/action-menu.stories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,24 @@ export default {
},
control: 'text',
},
quiet: {
name: 'quiet',
type: { name: 'boolean', required: false },
description: 'Quiet rendering',
table: {
type: { summary: 'boolean' },
defaultValue: { summary: false },
},
control: {
type: 'boolean',
},
},
},
args: {
visibleLabel: 'More Actions',
disabled: false,
open: false,
quiet: false,
},
};

Expand All @@ -72,13 +85,19 @@ interface StoryArgs {
customIcon?: string | TemplateResult;
selects?: 'single';
selected?: boolean;
quiet?: boolean;
}

const Template = (args: StoryArgs = {}): TemplateResult =>
ActionMenuMarkup(args);

export const Default = (args: StoryArgs = {}): TemplateResult => Template(args);

export const quiet = (args: StoryArgs = {}): TemplateResult => Template(args);
quiet.args = {
quiet: true,
};

export const selects = (args: StoryArgs = {}): TemplateResult =>
Template({
...args,
Expand Down
2 changes: 2 additions & 0 deletions packages/action-menu/stories/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export const ActionMenuMarkup = ({
changeHandler = (() => undefined) as (event: Event) => void,
disabled = false,
open = false,
quiet = false,
visibleLabel = '',
customIcon = '' as string | TemplateResult,
size = 'm' as 'm' | 's' | 'l' | 'xl' | 'xxl',
Expand All @@ -32,6 +33,7 @@ export const ActionMenuMarkup = ({
label=${ariaLabel}
?disabled=${disabled}
?open=${open}
?quiet=${quiet}
size=${size}
@change="${changeHandler}"
.selects=${selects ? selects : undefined}
Expand Down
6 changes: 3 additions & 3 deletions packages/card/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ Cards can be supplied an `actions` via a names slot.
alt="Demo Image"
/>
<div slot="footer">Footer</div>
<sp-action-menu slot="actions" placement="bottom-end">
<sp-action-menu slot="actions" placement="bottom-end" quiet>
<sp-menu-item>Deselect</sp-menu-item>
<sp-menu-item>Select Inverse</sp-menu-item>
<sp-menu-item>Feather...</sp-menu-item>
Expand Down Expand Up @@ -181,7 +181,7 @@ Quiet cards will also accept `actions` via a named slot.
<sp-card variant="quiet" heading="Card Heading" subheading="JPG Photo">
<img alt="" slot="preview" src="https://picsum.photos/200/300" />
<div slot="description">10/15/18</div>
<sp-action-menu slot="actions" placement="bottom-end">
<sp-action-menu slot="actions" placement="bottom-end" quiet>
<sp-menu-item>Deselect</sp-menu-item>
<sp-menu-item>Select Inverse</sp-menu-item>
<sp-menu-item>Feather...</sp-menu-item>
Expand Down Expand Up @@ -264,7 +264,7 @@ Or a `quiet` card:
>
<img src="https://picsum.photos/110" alt="Demo Image" slot="preview" />
<div slot="footer">Footer</div>
<sp-action-menu slot="actions" placement="bottom-end">
<sp-action-menu slot="actions" placement="bottom-end" quiet>
<sp-menu-item>Deselect</sp-menu-item>
<sp-menu-item>Select Inverse</sp-menu-item>
<sp-menu-item>Feather...</sp-menu-item>
Expand Down
10 changes: 5 additions & 5 deletions packages/card/stories/card.stories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ export const href = (args: StoryArgs): TemplateResult => {
Footer with a
<sp-link href="https://google.com">link to Google</sp-link>
</div>
<sp-action-menu slot="actions" placement="bottom-end">
<sp-action-menu slot="actions" placement="bottom-end" quiet>
<sp-menu-item>Deselect</sp-menu-item>
<sp-menu-item>Select Inverse</sp-menu-item>
<sp-menu-item>Feather...</sp-menu-item>
Expand All @@ -122,7 +122,7 @@ export const actions = (args: StoryArgs): TemplateResult => {
>
<img slot="cover-photo" src=${portrait} alt="Demo Graphic" />
<div slot="footer">Footer</div>
<sp-action-menu slot="actions" placement="bottom-end">
<sp-action-menu slot="actions" placement="bottom-end" quiet>
<sp-menu-item>Deselect</sp-menu-item>
<sp-menu-item>Select Inverse</sp-menu-item>
<sp-menu-item>Feather...</sp-menu-item>
Expand Down Expand Up @@ -233,7 +233,7 @@ export const quietActions = (args: StoryArgs): TemplateResult => {
>
<img src=${portrait} alt="Demo Graphic" slot="preview" />
<div slot="description">10/15/18</div>
<sp-action-menu slot="actions" placement="bottom-end">
<sp-action-menu slot="actions" placement="bottom-end" quiet>
<sp-menu-item>Deselect</sp-menu-item>
<sp-menu-item>Select Inverse</sp-menu-item>
<sp-menu-item>Feather...</sp-menu-item>
Expand Down Expand Up @@ -326,7 +326,7 @@ export const smallQuiet = (args: StoryArgs): TemplateResult => {
>
<img src=${portrait} alt="Demo Graphic" slot="preview" />
<div slot="footer">Footer</div>
<sp-action-menu slot="actions" placement="bottom-end">
<sp-action-menu slot="actions" placement="bottom-end" quiet>
<sp-menu-item>Deselect</sp-menu-item>
<sp-menu-item>Select Inverse</sp-menu-item>
<sp-menu-item>Feather...</sp-menu-item>
Expand Down Expand Up @@ -369,7 +369,7 @@ export const SlottedHeading = (args: StoryArgs): TemplateResult => {
quiet
></sp-textfield>
<div slot="subheading">Last modified on 6/17/2020, 3:37 PM</div>
<sp-action-menu slot="actions" placement="bottom-end">
<sp-action-menu slot="actions" placement="bottom-end" quiet>
<sp-menu-item>Deselect</sp-menu-item>
<sp-menu-item>Select Inverse</sp-menu-item>
<sp-menu-item>Feather...</sp-menu-item>
Expand Down
1 change: 1 addition & 0 deletions packages/card/test/card.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ describe('card', () => {
slot="actions"
placement="bottom-end"
label="More Actions"
quiet
>
<sp-menu>
<sp-menu-item>Deselect</sp-menu-item>
Expand Down
11 changes: 8 additions & 3 deletions packages/picker/src/Picker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -360,9 +360,6 @@ export class PickerBase extends SizedMixin(Focusable) {
popover.style.setProperty('--swc-menu-width', `100%`);
return;
}
if (this.quiet) return;
// only use `this.offsetWidth` when Standard variant
popover.style.setProperty('min-width', `${this.offsetWidth}px`);
}

private async closeMenu(): Promise<void> {
Expand Down Expand Up @@ -637,6 +634,14 @@ export class Picker extends PickerBase {
return [pickerStyles, chevronStyles];
}

protected override sizePopover(popover: HTMLElement): void {
super.sizePopover(popover);

if (this.quiet) return;
// only use `this.offsetWidth` when Standard variant
popover.style.setProperty('min-width', `${this.offsetWidth}px`);
}

protected override onKeydown = (event: KeyboardEvent): void => {
const { code } = event;
this.focused = true;
Expand Down
1 change: 1 addition & 0 deletions packages/top-nav/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ import { TopNav, TopNavItem } from '@spectrum-web-components/top-nav';
label="Account"
placement="bottom-end"
style="margin-inline-start: auto;"
quiet
>
<sp-menu-item>Account Settings</sp-menu-item>
<sp-menu-item>My Profile</sp-menu-item>
Expand Down
16 changes: 12 additions & 4 deletions packages/top-nav/stories/top-nav.stories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,11 @@ export const Default = (): TemplateResult => {
<sp-top-nav-item href="#page-4">
Page with Really Long Name
</sp-top-nav-item>
<sp-action-menu label="Account" style="margin-inline-start: auto;">
<sp-action-menu
label="Account"
style="margin-inline-start: auto;"
quiet
>
<sp-icon-settings slot="icon"></sp-icon-settings>
<sp-menu-item>Account Settings</sp-menu-item>
<sp-menu-item>My Profile</sp-menu-item>
Expand Down Expand Up @@ -77,7 +81,11 @@ export const Selected = (): TemplateResult => {
<sp-top-nav-item href="#page-4">
Page with Really Long Name
</sp-top-nav-item>
<sp-action-menu label="Account" style="margin-inline-start: auto;">
<sp-action-menu
label="Account"
style="margin-inline-start: auto;"
quiet
>
<sp-icon-settings slot="icon"></sp-icon-settings>
<sp-menu-item>Account Settings</sp-menu-item>
<sp-menu-item>My Profile</sp-menu-item>
Expand Down Expand Up @@ -108,7 +116,7 @@ class WrappedTopNav extends HTMLElement {
<sp-top-nav-item href="#page-4" autofocus>
Page with Really Long Name
</sp-top-nav-item>
<sp-action-menu label="Account" style="margin-inline-start: auto;">
<sp-action-menu label="Account" style="margin-inline-start: auto;" quiet>
<sp-icon-settings slot="icon"></sp-icon-settings>
<sp-menu-item>Account Settings</sp-menu-item>
<sp-menu-item>My Profile</sp-menu-item>
Expand Down Expand Up @@ -155,7 +163,7 @@ export const Modes = (): TemplateResult => {
<sp-action-button label="Link">
<sp-icon-link slot="icon"></sp-icon-link>
</sp-action-button>
<sp-action-menu label="User">
<sp-action-menu label="User" quiet>
<sp-avatar
slot="icon"
label="User avatar"
Expand Down

0 comments on commit 001e71c

Please sign in to comment.