-
Notifications
You must be signed in to change notification settings - Fork 2
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/expand component stories #21
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
51d50a1
chore: clean up cssin expand component
dannyk3941 8e65211
chore: clean up expand js and css
dannyk3941 cfeb6d4
chore: aria test
dannyk3941 05a7a68
Merge branch 'develop' into feat/expand-component-stories
dannyk3941 a740bec
fix: add aria attributes for expand pattern and md for expand doc
dannyk3941 71e3faa
Merge branch 'develop' into feat/expand-component-stories
dannyk3941 ecfd837
fix: add aria-controls attribute and id to expand component
dannyk3941 e22c554
fix: set aria attribute and IDs in expand.js and replace css w/ tokens
dannyk3941 35010f3
chore: change function for generate id in expand
dannyk3941 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
# Expand Pattern | ||
|
||
## Purpose | ||
|
||
The Expand patterns are simple interface patterns that allow the user to expand and collapse content. This component is similiar to the Accordion pattern but used for much simpler hide/show elements and may be nested within Accordion pattterns to show hierarchy. | ||
|
||
## Functional Requirements | ||
|
||
* Focus on the title will be set to the <button> element that is in the `.cbp-expand__title` <div> element | ||
|
||
## Technical Specifications | ||
|
||
### User Interactions | ||
|
||
* Click on the title will collapse/uncollapse the content of the expand component | ||
* Tab will focus on the button element of the Expand title but the actual title will *not* receive focus. | ||
|
||
### Responsiveness | ||
|
||
* Long titles will wrap and be spaced correctly so that wrapped text will fall under the text and not the button. | ||
|
||
### Accessibility | ||
|
||
* `aria-controls` is placed on the <button> of the Expand title and the value is set to the ID of the Expand content ID attribute. | ||
* `aria-expanded="true/false"` is placed on the button and changed with JS during open/close | ||
* Interactive elements must have an accessible name, `aria-labelledby` can be used to reference a different element to define it's accessible name. Since the button in the Expand title is a <button> with only an icon (svg), `aria-labelledby="expand-title"` is placed on the <span> element indicating the element ID that describes the button | ||
|
||
### Additional Notes and Considerations |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,61 +1,63 @@ | ||
export default { | ||
title: 'Patterns/Expand', | ||
argType: {}, | ||
parameters: { | ||
html: { | ||
root: '.wrapper' | ||
}, | ||
}, | ||
argTypes: { | ||
title: { | ||
name: 'Expand Title', | ||
description: 'Title of the Expand component to display', | ||
type: { name: 'string' } | ||
} | ||
}, | ||
decorators: [ | ||
(Story) =>`<div class="wrapper" style="margin-top: 2rem; margin-left: 2rem;">${Story().outerHTML || Story()}</div>` | ||
] | ||
}; | ||
|
||
const Template = () => { | ||
const ExpandTemplate = ({ title }) => { | ||
return ` | ||
<div class="cbp-expand"> | ||
<div class="cbp-expand__title"> | ||
<button> | ||
<button type="button"> | ||
<i class="fas fa-caret-down"></i> | ||
</button> | ||
<span> | ||
This is a question about where frogs live. | ||
</span> | ||
<span>${title}</span> | ||
</div> | ||
<div class="cbp-expand__content"> | ||
<ul class="cbp-expand__list"> | ||
<li>There are different species of frogs and some make great pets!</li> | ||
<li>Frogs can be bought at any pet store really. Here's a link to one <a href="http://petstore.com" | ||
class="cbp-text-link" target="_blank" rel="noopener noreferrer">petstore.com</a></li> | ||
</ul> | ||
</div> | ||
</div> | ||
<div class="cbp-expand"> | ||
<div class="cbp-expand__title"> | ||
<button> | ||
<i class="fas fa-caret-down"></i> | ||
</button> | ||
<span> | ||
This is a question about where frogs live. | ||
</span> | ||
</div> | ||
<div class="cbp-expand__content"> | ||
<ul class="cbp-expand__list"> | ||
<li>Frogs can be bought at any pet store really. Here's a link to one <a href="http://petstore.com" | ||
target="_blank" rel="noopener noreferrer">petstore.com</a></li> | ||
</ul> | ||
<p class="cbp-text-body">There are different species of frogs and some make great pets!</p> | ||
<p class="cbp-text-body cbp-margin-top-2x">Frogs can be bought at any pet store really. Here's a link to one <a href="http://petstore.com" class="cbp-text-link" target="_blank" rel="noopener noreferrer">petstore.com</a></p> | ||
</div> | ||
</div> | ||
`; | ||
}; | ||
|
||
const ExpandLongTitleTemplate = ({ title }) => { | ||
return ` | ||
<div class="cbp-expand"> | ||
<div class="cbp-expand__title"> | ||
<button> | ||
<button type="button"> | ||
<i class="fas fa-caret-down"></i> | ||
</button> | ||
<span> | ||
Some facts about dinosaurs and their eating habits that you should teach your kids. | ||
</span> | ||
<span id="expand-title">${title}</span> | ||
</div> | ||
<div class="cbp-expand__content"> | ||
<ul class="cbp-expand__list"> | ||
<li>Frogs can be bought at any pet store really. Here's a link to one <a href="http://petstore.com" | ||
target="_blank" rel="noopener noreferrer">petstore.com</a></li> | ||
</ul> | ||
<p class="cbp-text-body">There are different species of frogs and some make great pets!</p> | ||
<p class="cbp-text-body cbp-margin-top-2x">Frogs can be bought at any pet store really. Here's a link to one <a href="http://petstore.com" class="cbp-text-link" target="_blank" rel="noopener noreferrer">petstore.com</a></p> | ||
</div> | ||
</div> | ||
`; | ||
}; | ||
|
||
export const Expand = Template.bind({}); | ||
Expand.args = {}; | ||
export const Expand = ExpandTemplate.bind({}); | ||
Expand.args = { | ||
title: 'This is a question about where frogs live.' | ||
}; | ||
|
||
export const ExpandLongTitle = ExpandLongTitleTemplate.bind({}); | ||
ExpandLongTitle.args = { | ||
title: 'Some facts about dinosaurs and their eating habits that you should teach your kids.' | ||
}; | ||
ExpandLongTitle.storyName = 'Expand w/ Long Title'; |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The way I handle this is to querySelector() the button/control and control.click() it, deferring the logic to the button's click handler. I'm not sure if it automatically transfers focus to the button with that technique, but it can be done with 1 more line: control.focus()