Skip to content

Commit 2788f02

Browse files
ktranDevtools-frontend LUCI CQ
authored andcommitted
Restrict devtools-button to its content
Previously the devtools-button would listen to clicks outside of the actual button. Fixed: 380824706 Change-Id: Iec7df04a42c6710750d38ad31d2acd76029457a9 Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/6421818 Reviewed-by: Kateryna Prokopenko <[email protected]> Commit-Queue: Kateryna Prokopenko <[email protected]> Auto-Submit: Kim-Anh Tran <[email protected]>
1 parent 7148ffe commit 2788f02

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

front_end/ui/components/buttons/Button.test.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,30 @@ describe('Button', () => {
200200
assert.strictEqual(onKeydown.getCall(0).args[0].key, 'x');
201201
});
202202

203+
it('devtools-button width should not expand its content\'s width', () => {
204+
const button = new Buttons.Button.Button();
205+
button.data = {variant: Buttons.Button.Variant.PRIMARY};
206+
button.textContent = 'test';
207+
208+
const fullWidthContainer = document.createElement('div');
209+
fullWidthContainer.style.width = '400px';
210+
fullWidthContainer.style.height = '400px';
211+
fullWidthContainer.style.display = 'flex';
212+
fullWidthContainer.style.flexDirection = 'column';
213+
fullWidthContainer.appendChild(button);
214+
215+
renderElementIntoDOM(fullWidthContainer);
216+
const buttonWidth = button.getBoundingClientRect().width;
217+
const fullWidthContainerWidth = fullWidthContainer.getBoundingClientRect().width;
218+
assert.isBelow(buttonWidth, fullWidthContainerWidth);
219+
assert.isAbove(buttonWidth, 0);
220+
221+
const buttonHeight = button.getBoundingClientRect().height;
222+
const bigContainerHeight = fullWidthContainer.getBoundingClientRect().height;
223+
assert.isBelow(buttonHeight, bigContainerHeight);
224+
assert.isAbove(buttonHeight, 0);
225+
});
226+
203227
describe('in forms', () => {
204228
function renderForm(data: Buttons.Button.ButtonData = {
205229
variant: Buttons.Button.Variant.PRIMARY,

front_end/ui/components/buttons/button.css

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
display: inline-flex;
2929
flex-direction: row;
3030
align-items: center;
31+
width: fit-content;
3132
}
3233

3334
button {

0 commit comments

Comments
 (0)