Skip to content
Draft
Show file tree
Hide file tree
Changes from all 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
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ export const Base: Story = {
style={{ display: 'grid', gridTemplateColumns: '300px' }}
validated={args.validated}
value={args.value}
inline={args.inline}
>
<span slot="label">{args.label}</span>
<option value="1">New Hampshire</option>
Expand Down
11 changes: 11 additions & 0 deletions packages/pharos/src/components/combobox/pharos-combobox.scss
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,17 @@
width: 100%;
}

.combobox-wrapper {
display: flex;
align-items: center;
gap: var(--pharos-spacing-1-x);
}

label[for='input-element'].input-label--inline {
flex-shrink: 0;
margin-bottom: 0;
}

.combobox__icon {
fill: var(--pharos-combobox-color-icon-dropdown);
}
Expand Down
21 changes: 18 additions & 3 deletions packages/pharos/src/components/combobox/pharos-combobox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,13 @@ export class PharosCombobox extends ScopedRegistryMixin(FormMixin(FormElement))
@property({ type: Boolean, reflect: true, attribute: 'loose-match' })
public looseMatch = false;

/**
* Indicates if the label should be positioned inline with the input.
* @attr inline
*/
@property({ type: Boolean, reflect: true })
public inline = false;

/**
* The list of options available in the combobox dropdown list
* @readonly
Expand Down Expand Up @@ -458,8 +465,8 @@ export class PharosCombobox extends ScopedRegistryMixin(FormMixin(FormElement))
}

protected override render(): TemplateResult {
return html`
<label for="input-element" id="input-label">
const content = html`
<label for="input-element" id="input-label" class=${this.inline ? 'input-label--inline' : ''}>
<slot name="label"></slot>
${this.requiredIndicator}
</label>
Expand Down Expand Up @@ -489,7 +496,15 @@ export class PharosCombobox extends ScopedRegistryMixin(FormMixin(FormElement))
/>
${this._renderClearButton()} ${this._renderIconButton()} ${this._renderList()}
</div>
${this.messageContent}
`;

if (this.inline) {
return html`
<div class="combobox-wrapper">${content}</div>
${this.messageContent}
`;
} else {
return html` ${content} ${this.messageContent} `;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ export const Base: Story = {
.placeholder=${args.placeholder}
message=${ifDefined(args.message)}
.required=${args.required}
.inline=${args.inline}
style="display: grid; grid-template-columns: 300px;"
>
<span slot="label">${args.label}</span>
Expand Down
2 changes: 2 additions & 0 deletions packages/pharos/src/components/combobox/storyArgs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export interface ComponentArgs {
required?: boolean;
validated?: boolean;
value?: string;
inline?: boolean;
}

export type StoryArgs = ComponentArgs & {};
Expand All @@ -28,4 +29,5 @@ export const defaultArgs: StoryArgs = {
required: false,
validated: false,
value: '',
inline: false,
};