From 47144b9ee4afd9f1dec9e6e66f7b38f75bdf31e9 Mon Sep 17 00:00:00 2001 From: Aaron Bohy Date: Wed, 29 Apr 2020 07:21:29 +0000 Subject: [PATCH] [IMP] web: list: improve style of icon buttons Buttons with icon and string attributes now have both their icon and string displayed, whereas before only the icon was displayed (the string was available as title). We also force class btn-link to style buttons with icon, except if another btn-xxx class is explicitely provided. Part of task 2195254 --- .../static/src/js/views/list/list_renderer.js | 13 +++++++-- addons/web/static/src/scss/list_view.scss | 3 +++ addons/web/static/tests/views/list_tests.js | 27 +++++++++++++++++++ 3 files changed, 41 insertions(+), 2 deletions(-) diff --git a/addons/web/static/src/js/views/list/list_renderer.js b/addons/web/static/src/js/views/list/list_renderer.js index 68a449a9246..13deb446c1c 100644 --- a/addons/web/static/src/js/views/list/list_renderer.js +++ b/addons/web/static/src/js/views/list/list_renderer.js @@ -469,9 +469,18 @@ var ListRenderer = BasicRenderer.extend({ var self = this; var nodeWithoutWidth = Object.assign({}, node); delete nodeWithoutWidth.attrs.width; + + let extraClass = ''; + if (node.attrs.icon) { + // if there is an icon, we force the btn-link style, unless a btn-xxx + // style class is explicitely provided + const btnStyleRegex = /\bbtn-(primary|secondary|link|success|info|warning|danger)\b/; + if (!btnStyleRegex.test(nodeWithoutWidth.attrs.class)) { + extraClass = 'btn-link o_icon_button'; + } + } var $button = viewUtils.renderButtonFromNode(nodeWithoutWidth, { - extraClass: node.attrs.icon ? 'o_icon_button' : undefined, - textAsTitle: !!node.attrs.icon, + extraClass: extraClass, }); this._handleAttributes($button, node); this._registerModifiers(node, record, $button); diff --git a/addons/web/static/src/scss/list_view.scss b/addons/web/static/src/scss/list_view.scss index a9076270ed2..4c0633cf0f3 100644 --- a/addons/web/static/src/scss/list_view.scss +++ b/addons/web/static/src/scss/list_view.scss @@ -42,6 +42,9 @@ width: 17px; height: 17px; } + &.o_list_button .o_button_icon { + margin-right: 3px; + } } tfoot { diff --git a/addons/web/static/tests/views/list_tests.js b/addons/web/static/tests/views/list_tests.js index 785b3864e8d..913d75ed8bf 100644 --- a/addons/web/static/tests/views/list_tests.js +++ b/addons/web/static/tests/views/list_tests.js @@ -277,6 +277,33 @@ QUnit.module('Views', { list.destroy(); }); + QUnit.test('list view with icon buttons', async function (assert) { + assert.expect(5); + + this.data.foo.records.splice(1); + + const list = await createView({ + View: ListView, + model: 'foo', + data: this.data, + arch: ` + +