-
Notifications
You must be signed in to change notification settings - Fork 45
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
Get full box width of element #45
Comments
There might be a better way to get this, right now I wrote myself a helper function function getFullWidth(el) {
var rightMargin = el.getRawStyle('margin-right');
rightMargin = rightMargin.replace('px', '');
rightMargin = parseInt(rightMargin);
var leftMargin = el.getRawStyle('margin-right');
leftMargin = leftMargin.replace('px', '');
leftMargin = parseInt(leftMargin);
return el.width.plus(rightMargin).plus(leftMargin);
} This would also need to handle |
Looks good. This is definitely something worth adding. I'm not sure about the 'fullWidth' descriptor, though. Would Also, I believe getRawStyle() converts everything to |
@JuanCaicedo BTW, there's a bug in your helper function: |
Copy paste error 😅 |
@jamesshore I can take a stab at implementing this and add any questions I have 😄 |
Agreed on padding. I'm not sure about borders as they have special cases, but it might be worth doing. I'd prefer to take each one as a separate pull request in any case. Let's think this through a bit more first... eventually, when we do borders, we will want to be able to say things like So, for consistency, perhaps what we need here is:
What do you think? Am I missing anything? |
Some more ideas for If so, then we should probably use |
I think I lean towards being able to split I would then imagine that If we pursue the above, I'm not sure how to handle |
I'd say |
Although I'm not sure about Perhaps it should be called |
That makes sense, I'm good with |
My guess is that these, along with the logic for getting them, would need to be added in https://github.com/jamesshore/quixote/blob/master/src/q_element.js#L32? |
The proper way to implement this is to create a new descriptor. This guide explains how. |
Also, your descriptor should extend |
@JuanCaicedo I've been thinking about margins. I think there might be a better option. The problem with margins is that they're an implementation detail. The idea of Quixote is that it allows you to talk about the visual appearance of your page. From a visual perspective, margins don't exist, at least not in the same way that they do in CSS. (Borders and padding, in contrast, do have a direct correspondence in the page.) Instead of margins, the viewer sees white space. Margins are a way of achieving white space, and because they collapse and combine there's no direct visual connection between the As a result, I think we might be better off providing ways to talk about white space rather than margins. Specifically, the distance between elements. I'm proposing something like this: Then, to talk about how two columns fill up your body element, you might say this: // first and second fill up the entire body
body.assert({
left: first.left,
right: second.right,
width: first.left.to(second.right)
});
// There's a ten-pixel gutter between first and second
// (This uses a new assertion API that I've been planning)
first.right.to(second.left).should.equal(10); We might even want to provide a convenience API for this: body.should.be.filled(first, 10, second); // element, gutter, element What do you think? |
I think I'm on board. I can picture this being useful in addition to the border stuff we're discussing above. For example, when I implemented the styles for the categories section of this page, it would have been nice to be able to make an assertion about how much space there was from the right edge of the text to the left edge of the border. It seems like what would need to be implemented is a new function |
Are you writing keeping track of your thoughts for that new assertion API in an issue? I might like to drop some thoughts in as well 😃 |
Good idea. See #47. |
Regarding the |
@JuanCaicedo I've updated the Descriptor tutorial. The changes are mostly minor but you might find it useful. |
@jamesshore I've been thinking about this some more, and I'm not sure it will exactly work for the case I'm trying to test. If you think about a case like the one I show in this codepen, I think an assertion like the following would fail: parent.assert({
width: first.left.to(second.right)
}) I think this would actually also fail if you manually factor in the width of the margin (since it takes up width on both the left and right. parent.assert({
width: first.left.to(second.right).plus(second.margin.width)
}) To fully account for this, you would need to factor in both margins parent.assert({
width: first.left.to(second.right).plus(second.margin.left.width).plus(second.margin.right.width)
}) This makes me think that What are your thoughts? |
@JuanCaicedo I'm not following. In plain English, what about that codepen are you trying to check? Is it the gap between the green box and the red box, or something else? |
The same as the example above, that the whole width of the parent is taken up by the two children |
Except it's not, is it? There's a five-pixel gap between
first.left.should.equal(parent.left);
first.right.to.second.left.should.equal(5);
second.right.to.parent.right.should.equal(5);
// or maybe...
parent.should.be.filled(first, 5, second, 5) |
Yeah, I think we have the same understanding. I just don't think that this type of assertion should require knowledge about the margin, that seems like testing implementation details |
I'm still confused--what knowledge of the margin is involved in the example I gave? There's knowledge that there's a gap, but that's a visual feature that presumably you'd want to test. If you just want to test that the two elements fill the entire parent, with a five pixel gap on the right, you could do it this way: parent.assert({
width: first.left.to(second.right).plus(5)
}); Ultimately, the child elements don't fill the parent--there's that gap on the right--so any test that says they do should fail. first.left.to(second.right).should.equal(parent.width);
// Outputs:
// Distance from left edge of 'first' to right edge of 'second' should be 5px larger.
// Expected: 200px (width of 'parent')
// But was: 195px |
Okay, now it makes sense 😃 I was thinking that you'd want to avoid needing to specify 5 so that you're testing at a higher level, but your reasoning makes sense. You should have to specify that gap, because it's what the user is experiencing |
PositionDescriptor.to() has been added and will be included in the 0.13 release. |
I want to have a test case where I want to assert that an element takes up the full width of the parent minus the width of its sibling.
However, this breaks when the second element has a margin, because margins are not included as part of the width.
My solution involves manually factoring in the width of the padding, but it would be nice to have something along the lines of
The text was updated successfully, but these errors were encountered: