Skip to content
Merged
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
12 changes: 2 additions & 10 deletions elements/pfe-accordion/demo/pfe-accordion.story.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,20 +53,12 @@ stories.add(PfeAccordion.tag, () => {
});

// Ask user if they want to add any custom content
const customContent = storybookBridge.boolean(
"Use custom content?",
false,
"Content"
);
const customContent = storybookBridge.boolean("Use custom content?", false, "Content");

// Let the user customize the header + panel set
if (customContent) {
for (let i = 0; i < accordionCount; i++) {
headings[i] = storybookBridge.text(
`Heading ${i + 1}`,
"",
"accordion-set"
);
headings[i] = storybookBridge.text(`Heading ${i + 1}`, "", "accordion-set");
panels[i] = storybookBridge.text(`Panel ${i + 1}`, "", "accordion-set");
}
}
Expand Down
39 changes: 10 additions & 29 deletions elements/pfe-accordion/src/pfe-accordion.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,19 +86,11 @@ class PfeAccordion extends PFElement {

if (attr === "pfe-disclosure") {
if (newVal === "true") {
this._allHeaders().forEach(header =>
header.setAttribute("pfe-disclosure", "true")
);
this._allPanels().forEach(panel =>
panel.setAttribute("pfe-disclosure", "true")
);
this._allHeaders().forEach(header => header.setAttribute("pfe-disclosure", "true"));
this._allPanels().forEach(panel => panel.setAttribute("pfe-disclosure", "true"));
} else {
this._allHeaders().forEach(header =>
header.setAttribute("pfe-disclosure", "false")
);
this._allPanels().forEach(panel =>
panel.setAttribute("pfe-disclosure", "false")
);
this._allHeaders().forEach(header => header.setAttribute("pfe-disclosure", "false"));
this._allPanels().forEach(panel => panel.setAttribute("pfe-disclosure", "false"));
}
}
}
Expand Down Expand Up @@ -180,10 +172,7 @@ class PfeAccordion extends PFElement {
});

if (headers.length === 1) {
if (
this.hasAttribute("pfe-disclosure") &&
this.getAttribute("pfe-disclosure") === "false"
) {
if (this.hasAttribute("pfe-disclosure") && this.getAttribute("pfe-disclosure") === "false") {
return;
}

Expand Down Expand Up @@ -222,9 +211,7 @@ class PfeAccordion extends PFElement {

_expandPanel(panel) {
if (!panel) {
console.error(
`${PfeAccordion.tag}: Trying to expand a panel that doesn't exist`
);
console.error(`${PfeAccordion.tag}: Trying to expand a panel that doesn't exist`);
return;
}

Expand All @@ -244,9 +231,7 @@ class PfeAccordion extends PFElement {

_collapsePanel(panel) {
if (!panel) {
console.error(
`${PfeAccordion.tag}: Trying to collapse a panel that doesn't exist`
);
console.error(`${PfeAccordion.tag}: Trying to collapse a panel that doesn't exist`);
return;
}

Expand Down Expand Up @@ -339,9 +324,7 @@ class PfeAccordion extends PFElement {
}

if (next.tagName.toLowerCase() !== PfeAccordionPanel.tag) {
console.error(
`${PfeAccordion.tag}: Sibling element to a header needs to be a panel`
);
console.error(`${PfeAccordion.tag}: Sibling element to a header needs to be a panel`);
return;
}

Expand All @@ -350,15 +333,13 @@ class PfeAccordion extends PFElement {

_previousHeader() {
const headers = this._allHeaders();
let newIndex =
headers.findIndex(header => header === document.activeElement) - 1;
let newIndex = headers.findIndex(header => header === document.activeElement) - 1;
return headers[(newIndex + headers.length) % headers.length];
}

_nextHeader() {
const headers = this._allHeaders();
let newIndex =
headers.findIndex(header => header === document.activeElement) + 1;
let newIndex = headers.findIndex(header => header === document.activeElement) + 1;
return headers[newIndex % headers.length];
}

Expand Down
7 changes: 1 addition & 6 deletions elements/pfe-autocomplete/demo/pfe-autocomplete.story.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
import { storiesOf } from "@storybook/polymer";
import {
withKnobs,
text,
select,
boolean
} from "@storybook/addon-knobs/polymer";
import { withKnobs, text, select, boolean } from "@storybook/addon-knobs/polymer";
import * as storybookBridge from "@storybook/addon-knobs/polymer";
import PfeAutocomplete from "../dist/pfe-autocomplete";
import * as tools from "../../../.storybook/utils.js";
Expand Down
97 changes: 21 additions & 76 deletions elements/pfe-autocomplete/src/pfe-autocomplete.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,19 +42,15 @@ class PfeAutocomplete extends PFElement {
this._slotchangeHandler = this._slotchangeHandler.bind(this);

this._slot = this.shadowRoot.querySelector("slot");
this._slot.addEventListener(
PfeAutocomplete.events.slotchange,
this._slotchangeHandler
);
this._slot.addEventListener(PfeAutocomplete.events.slotchange, this._slotchangeHandler);
}

connectedCallback() {
super.connectedCallback();

this.loading = false;
this.debounce = this.debounce || 300;
this._ariaAnnounceTemplate =
"There are ${numOptions} suggestions. Use the up and down arrows to browse.";
this._ariaAnnounceTemplate = "There are ${numOptions} suggestions. Use the up and down arrows to browse.";

// clear button
this._clearBtn = this.shadowRoot.querySelector(".clear-search");
Expand All @@ -72,31 +68,16 @@ class PfeAutocomplete extends PFElement {
this.addEventListener("keyup", this._inputKeyUp.bind(this));

// these two events, fire search
this.addEventListener(
PfeAutocomplete.events.search,
this._closeDroplist.bind(this)
);
this.addEventListener(
PfeAutocomplete.events.select,
this._optionSelected.bind(this)
);
this.addEventListener(PfeAutocomplete.events.search, this._closeDroplist.bind(this));
this.addEventListener(PfeAutocomplete.events.select, this._optionSelected.bind(this));
}

disconnectedCallback() {
this.removeEventListener("keyup", this._inputKeyUp);

this.removeEventListener(
PfeAutocomplete.events.search,
this._closeDroplist
);
this.removeEventListener(
PfeAutocomplete.events.select,
this._optionSelected
);
this._slot.removeEventListener(
PfeAutocomplete.events.slotchange,
this._slotchangeHandler
);
this.removeEventListener(PfeAutocomplete.events.search, this._closeDroplist);
this.removeEventListener(PfeAutocomplete.events.select, this._optionSelected);
this._slot.removeEventListener(PfeAutocomplete.events.slotchange, this._slotchangeHandler);
if (this._input) {
this._input.removeEventListener("input", this._inputChanged);
this._input.removeEventListener("blur", this._closeDroplist);
Expand Down Expand Up @@ -212,19 +193,15 @@ class PfeAutocomplete extends PFElement {
let slotElems = slotNodes.filter(n => n.nodeType === Node.ELEMENT_NODE);

if (slotElems.length === 0) {
console.error(
`${PfeAutocomplete.tag}: There must be a input tag in the light DOM`
);
console.error(`${PfeAutocomplete.tag}: There must be a input tag in the light DOM`);

return;
}

this._input = slotElems[0];

if (this._input.tagName.toLowerCase() !== "input") {
console.error(
`${PfeAutocomplete.tag}: The only child in the light DOM must be an input tag`
);
console.error(`${PfeAutocomplete.tag}: The only child in the light DOM must be an input tag`);

return;
}
Expand All @@ -246,8 +223,7 @@ class PfeAutocomplete extends PFElement {
this._input.setAttribute("autocapitalize", "off");
this._input.setAttribute("spellcheck", "false");

this._dropdown._ariaAnnounceTemplate =
this.getAttribute("aria-announce-template") || this._ariaAnnounceTemplate;
this._dropdown._ariaAnnounceTemplate = this.getAttribute("aria-announce-template") || this._ariaAnnounceTemplate;
}

_inputChanged() {
Expand Down Expand Up @@ -321,10 +297,7 @@ class PfeAutocomplete extends PFElement {
_sendAutocompleteRequest(input) {
if (!this.autocompleteRequest) return;

this.autocompleteRequest(
{ query: input },
this._autocompleteCallback.bind(this)
);
this.autocompleteRequest({ query: input }, this._autocompleteCallback.bind(this));
}

_autocompleteCallback(response) {
Expand All @@ -342,9 +315,7 @@ class PfeAutocomplete extends PFElement {

_activeOption(activeIndex) {
if (activeIndex === null || activeIndex === "null") return;
return this._dropdown.shadowRoot.querySelector(
"li:nth-child(" + (parseInt(activeIndex, 10) + 1) + ")"
).innerHTML;
return this._dropdown.shadowRoot.querySelector("li:nth-child(" + (parseInt(activeIndex, 10) + 1) + ")").innerHTML;
}

_inputKeyUp(e) {
Expand All @@ -369,10 +340,7 @@ class PfeAutocomplete extends PFElement {
return;
}

activeIndex =
activeIndex === null || activeIndex === "null"
? optionsLength
: parseInt(activeIndex, 10);
activeIndex = activeIndex === null || activeIndex === "null" ? optionsLength : parseInt(activeIndex, 10);

activeIndex -= 1;

Expand All @@ -386,10 +354,7 @@ class PfeAutocomplete extends PFElement {
return;
}

activeIndex =
activeIndex === null || activeIndex === "null"
? -1
: parseInt(activeIndex, 10);
activeIndex = activeIndex === null || activeIndex === "null" ? -1 : parseInt(activeIndex, 10);
activeIndex += 1;

if (activeIndex > optionsLength - 1) {
Expand All @@ -413,10 +378,7 @@ class PfeAutocomplete extends PFElement {
}

if (activeIndex !== null && activeIndex !== "null") {
this._input.setAttribute(
"aria-activedescendant",
"option-" + activeIndex
);
this._input.setAttribute("aria-activedescendant", "option-" + activeIndex);
} else {
this._input.setAttribute("aria-activedescendant", "");
}
Expand Down Expand Up @@ -456,9 +418,7 @@ class PfeSearchDroplist extends PFElement {
connectedCallback() {
super.connectedCallback();

this._ariaAnnounce = this.shadowRoot.querySelector(
".suggestions-aria-help"
);
this._ariaAnnounce = this.shadowRoot.querySelector(".suggestions-aria-help");

this.activeIndex = null;
this._ul = this.shadowRoot.querySelector("ul");
Expand All @@ -485,10 +445,7 @@ class PfeSearchDroplist extends PFElement {
let ariaAnnounceText = "";

if (this._ariaAnnounceTemplate) {
ariaAnnounceText = this._ariaAnnounceTemplate.replace(
"${numOptions}",
options.length
);
ariaAnnounceText = this._ariaAnnounceTemplate.replace("${numOptions}", options.length);
}

this._ariaAnnounce.textContent = ariaAnnounceText;
Expand Down Expand Up @@ -522,35 +479,23 @@ class PfeSearchDroplist extends PFElement {
}

_activeIndexChanged() {
if (
!this.data ||
this.data.length === 0 ||
this.activeIndex === null ||
this.activeIndex === "null"
)
return;
if (!this.data || this.data.length === 0 || this.activeIndex === null || this.activeIndex === "null") return;

// remove active class
if (this._ul.querySelector(".active")) {
this._ul.querySelector(".active").classList.remove("active");
}

// add active class to selected option
let activeOption = this._ul.querySelector(
"li:nth-child(" + (parseInt(this.activeIndex, 10) + 1) + ")"
);
let activeOption = this._ul.querySelector("li:nth-child(" + (parseInt(this.activeIndex, 10) + 1) + ")");

activeOption.classList.add("active");

// scroll to selected element when selected item with keyboard is out of view
let ulWrapper = this.shadowRoot.querySelector(".droplist");
let activeOptionHeight = activeOption.offsetHeight;
activeOptionHeight += parseInt(
window.getComputedStyle(activeOption).getPropertyValue("margin-bottom"),
10
);
ulWrapper.scrollTop =
activeOption.offsetTop - ulWrapper.offsetHeight + activeOptionHeight;
activeOptionHeight += parseInt(window.getComputedStyle(activeOption).getPropertyValue("margin-bottom"), 10);
ulWrapper.scrollTop = activeOption.offsetTop - ulWrapper.offsetHeight + activeOptionHeight;
}

get open() {
Expand Down
13 changes: 4 additions & 9 deletions elements/pfe-avatar/demo/pfe-avatar.story.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading