Skip to content

Commit

Permalink
fix(table): adjust border size depending on devicePixelRatio [which d…
Browse files Browse the repository at this point in the history
…epends on page zoom level] so we do not lose table cell borders
  • Loading branch information
mfo committed Nov 25, 2024
1 parent 0c6dbc8 commit 16ee0ca
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
20 changes: 20 additions & 0 deletions app/javascript/controllers/fix_table_border_controller.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { ApplicationController } from './application_controller';

export class FixTableBorderController extends ApplicationController {
connect() {
const pixelSize = Math.round((1 / window.devicePixelRatio) * 100) / 100;

// Safari does not support devicePixelRatio
if (navigator.userAgent.indexOf('Safari') > -1) {
return;
}

const fix = document.createElement('style');
fix.innerText = `
.fr-table.fr-table--bordered .fr-table__content th,
.fr-table.fr-table--bordered .fr-table__content td {
background-size: 100% ${pixelSize}px, ${pixelSize}px 100%}
}`;
document.body.appendChild(fix);
}
}
2 changes: 1 addition & 1 deletion app/views/layouts/application.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
= yield(:invisible_captcha_styles)
= render partial: 'layouts/setup_theme'

%body{ { id: content_for(:page_id), class: browser.platform.ios? ? 'ios' : nil, data: { controller: 'turbo number-input' } }.compact }
%body{ { id: content_for(:page_id), class: browser.platform.ios? ? 'ios' : nil, data: { controller: 'turbo number-input fix-table-border' } }.compact }
= render partial: 'layouts/skiplinks'
= render partial: 'layouts/display_theme_modal'

Expand Down

0 comments on commit 16ee0ca

Please sign in to comment.