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

Feat/select element #34

Merged
merged 5 commits into from
Jun 6, 2023
Merged
Show file tree
Hide file tree
Changes from 3 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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
106 changes: 106 additions & 0 deletions packages/vanilla/src/components/select/select.stories.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
export default {
title: 'Patterns',
parameters: {
html: {
root: '.cbp-form'
}
},
argTypes: {
label: {
name: 'Label Element',
description: 'Represents a caption for the `<select>` element in the user interface.',
control: { type: 'text' }
},
inputDescription: {
name: 'Input Description',
description: 'Instructions or supplementary information regarding the `<select>` element.',
control: { type: 'text' }
},
labelFor: {
name: 'Label `for` Attribute',
description: 'Indicates the form element that this `<label>` describes and has the value which is the `id` of the `<select>` element it relates to.',
control: { type: 'text' }
},
formControlName: {
name: 'Input `name` Attribute',
description: 'Name of the form control in the input element. Submitted with the form as part of a name/value pair.',
control: { type: 'text' }
},
placeholderOption: {
name: 'Placeholder Option Text',
description: 'Text of the placeholder option.',
control: { type: 'text' }
},
errorMessage: {
name: 'Error Message',
description: 'A message in the input description that a problem has occurred.',
control: { type: 'text' }
},
optionsObj: {
name: 'Options Object',
description: 'Sets the label of the `<option>` and the `value` attribute.',
control: { type: 'object' }
},
disabled: {
name: '`disabled` Attribute',
description: 'Attribute that indicates that the user cannot interact with the control.',
control: { type: 'boolean' }
}
},
decorators: [
(Story, context) => `
<form class="cbp-form">
<label for=${context.args.labelFor} class="cbp-input__label">${context.args.label}</label>
<p class="cbp-input__description" ${!context.args.required ? '' : 'hidden'}>${context.args.inputDescription}</p>
Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't see a required control that would set this. See my higher-level comment about this though.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Forgot this control, should be added now along with the aria-required attribute. Toggling this control will show the css of the :invalid pseudo-class but regarding your comment below, we should revisit/discuss and finalize how to implement this along with the error message class.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yeah, I'm not sure why it would show the :invalid styling. Is this because you're still using the required attribute as well? This is certainly not desired behavior on an unfilled form and would be another reason not to use required.

<p class="cbp-input__description ${context.args.required ? 'cbp-input__description--error': ''}" ${context.args.required ? '' : 'hidden'}><i class="fas fa-exclamation-triangle"></i>${context.args.errorMessage}</p>
${Story().outerHTML || Story()}
</form>
`
]
}

const Template = ({ labelFor, formControlName, placeholderOption, disabled, optionsObj: { option1, option2, option3, option4, option5} }) => (
`
<select class="cbp-input__select" name=${formControlName} id=${labelFor} ${disabled ? 'disabled' : ''}>
<option value="" selected>${placeholderOption}</option>
Copy link
Collaborator

Choose a reason for hiding this comment

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

We don't need selected on the first option. It will be the default anyway.

The presentation of this option looks like something is selected. I think we need to establish a best practice here rather than make it an editable control/option. At SSA we used "--" for the default/no selection because it cannot be mistaken for a selection. USWDS uses "- Select -" which is also common. Because the label says what the thing is being selected, we don't need to repeat it here though - either of the above options would be a better choice and we should not let the user customize it in Storybook to make bad decisions.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed the control and replaced with -- Select --

<option value=${option1.value}>${option1.label}</option>
<option value=${option2.value}>${option2.label}</option>
<option value=${option3.value}>${option3.label}</option>
<option value=${option4.value}>${option4.label}</option>
<option value=${option5.value}>${option5.label}</option>
</select>
`
)

export const Select = Template.bind({});
Select.args = {
label: 'Port of Departure',
labelFor: 'port',
inputDescription: 'Required.',
formControlName: 'departurePort',
placeholderOption: 'Choose Port',
errorMessage: 'This field is required.',
optionsObj: {
option1: {
value: 'baltimore',
label: 'Port of Baltimore'
},
option2: {
value: 'boston',
label: 'Port of Boston'
},
option3: {
value: 'philadelphia',
label: 'Port of Philadelphia'
},
option4: {
value: 'washington',
label: 'Port of Washington'
},
option5: {
value: 'zoolily',
label: 'Port of Zoolily'
},
},
disabled: false
};
3 changes: 1 addition & 2 deletions packages/vanilla/src/sass/base/_core.scss
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@ button {
[aria-disabled=true],
:disabled,
input:read-only:not([type="checkbox"], [type="radio"], [type="file"], [type="range"], [type="color"]),
textarea:read-only,
select:read-only {
textarea:read-only {
cursor: not-allowed;
}

Expand Down
2 changes: 1 addition & 1 deletion packages/vanilla/src/sass/components/_index.scss
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
@use './overflow-menu';
@use './pagination';
@use 'radio';
@use './select';
@use 'select';
@use 'slider';
@use 'tabs';
@use 'text-input';
Expand Down
152 changes: 0 additions & 152 deletions packages/vanilla/src/sass/components/_select.scss

This file was deleted.

40 changes: 40 additions & 0 deletions packages/vanilla/src/sass/components/select/_index.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
.cbp-input__select {
appearance: none;
background-color: var(--cbp-color-white);
background-image: url('/assets/images/angle-arrow-down-gray-90.svg');
background-repeat: no-repeat;
background-position: right var(--cbp-space-2x) center;
background-size: var(--cbp-space-3x) var(--cbp-space-3x);
border-color: var(--cbp-color-interactive-neutral-base);
border-radius: var(--cbp-border-radius-soft);
border-width: var(--cbp-border-size-md);
color: var(--cbp-color-text-darkest);
min-height: var(--cbp-space-9x);
outline: 0;
padding-left: var(--cbp-space-2x);
width: 100%;

&:hover {
border-color: var(--cbp-color-base-neutral-darker);
}

&:focus {
border-color: var(--cbp-color-interactive-focus-dark);
}

&:disabled {
background-color: var(--cbp-color-interactive-disabled-light);
border-color: var(--cbp-color-interactive-disabled-dark);
font-style: italic;

&:hover {
border-color: var(--cbp-color-base-neutral-darker);
}
}

&:invalid {
background-color: var(--cbp-color-danger-lighter);
border-color: var(--cbp-color-danger-dark);
font-style: italic;
}
}