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

Adding back selected-parent class #713

Merged
merged 2 commits into from
Dec 27, 2016
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
22 changes: 18 additions & 4 deletions services/components/select.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ var _ = require('lodash'),
visibleComponents = require('./visible-components'),
hidden = 'kiln-hide',
selectorHeight = 56, // selector menus are 48px tall, offset is 8px
currentSelected;
currentSelected,
currentSelectedParent;

/**
* Get the closest component element from the DOM. Checks self and then parents.
Expand Down Expand Up @@ -108,7 +109,8 @@ function removePadding() {
* @param {MouseEvent} e
*/
function select(el) {
var component = getComponentEl(el);
var component = getComponentEl(el),
parent = getParentEl(component);

// only one component can be selected at a time
unselect();
Expand All @@ -120,21 +122,28 @@ function select(el) {
component.classList.add('kiln-suppress-animation');
}

// selected component gets .selected, parent gets .selected-parent
// selected component gets .selected
if (component && component.tagName !== 'HTML') {
component.classList.add('selected');
addPadding(component);
currentSelected = component;
}

// if there's a parent it gets .selected-parent
if (parent) {
parent.classList.add('selected-parent');
currentSelectedParent = parent;
}

window.kiln.trigger('select', component);
}

/**
* remove selection
*/
function unselect() {
var current = currentSelected || dom.find('.component-selector-wrapper.selected');
var current = currentSelected || dom.find('.component-selector-wrapper.selected'),
currentParent = current ? currentSelectedParent || getParentEl(current) : null;

if (current) {
current.classList.remove('kiln-suppress-animation'); // unsuppress initialFadeInOut animation
Expand All @@ -143,7 +152,12 @@ function unselect() {
window.kiln.trigger('unselect', current);
}

if (currentParent) {
currentParent.classList.remove('selected-parent');
}

currentSelected = null;
currentSelectedParent = null;
}

/**
Expand Down
25 changes: 25 additions & 0 deletions services/components/select.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,18 @@ describe(dirname, function () {
fn(el);
expect(el.classList.contains('selected')).to.equal(true);
});

it('adds .selected-parent class to parent component', function () {
var el = stubEditableElement(),
parent = stubComponent(),
component = stubComponent();

component.appendChild(el);
parent.appendChild(component);

fn(el);
expect(parent.classList.contains('selected-parent')).to.equal(true);
});
});

describe('unselect', function () {
Expand All @@ -70,6 +82,19 @@ describe(dirname, function () {
fn(); // unselect
expect(component.classList.contains('selected')).to.equal(false);
});

it('removed .selected-parent class from component parent', function () {
var el = stubEditableElement(),
component = stubComponent(),
parent = stubComponent();

component.appendChild(el);
parent.appendChild(component);

lib.select(el);
fn(); // unselect
expect(parent.classList.contains('selected-parent')).to.equal(false);
});
});

describe('when', function () {
Expand Down