|
| 1 | +Depicting availability of interface elements |
| 2 | +############################################ |
| 3 | + |
| 4 | +The state of interface elements is a crucial aspect of user interface design, providing visual feedback and preventing interaction when certain actions aren't allowed. |
| 5 | + |
| 6 | +Working with tabs |
| 7 | +***************** |
| 8 | + |
| 9 | +Mautic uses the following CSS code to style tabs which aren't available for interaction: |
| 10 | + |
| 11 | +.. code-block:: css |
| 12 | +
|
| 13 | + .nav-tabs.nav-tabs-contained > li.disabled { |
| 14 | + cursor: not-allowed; |
| 15 | + color: var(--text-disabled); |
| 16 | + } |
| 17 | +
|
| 18 | + .nav-tabs.nav-tabs-contained > li.disabled > a { |
| 19 | + background-color: var(--button-disabled); |
| 20 | + pointer-events: none; |
| 21 | + } |
| 22 | +
|
| 23 | +This CSS accomplishes the following: |
| 24 | + |
| 25 | +* Sets the cursor to ``not-allowed`` for tabs which can't be interacted with, indicating that interaction is prohibited. |
| 26 | +* Changes the text color to a predefined inactive state color. |
| 27 | +* Modifies the background color of the tab to visually represent its inactive state. |
| 28 | +* Prevent click events on the tab using ``pointer-events: none``. |
| 29 | + |
| 30 | +To dynamically deactivate tabs, use JavaScript to add or remove the ``disabled`` class. Here's an example function: |
| 31 | + |
| 32 | +.. code-block:: javascript |
| 33 | +
|
| 34 | + Mautic.togglePermissionVisibility = function () { |
| 35 | + setTimeout(function () { |
| 36 | + if (mQuery('#role_isAdmin_0').prop('checked')) { |
| 37 | + mQuery('#permissions-tab').removeClass('disabled'); |
| 38 | + } else { |
| 39 | + mQuery('#permissions-tab').addClass('disabled'); |
| 40 | + } |
| 41 | + }, 10); |
| 42 | + }; |
| 43 | +
|
| 44 | +This function: |
| 45 | + |
| 46 | +* Checks the state of a checkbox - ``#role_isAdmin_0``. |
| 47 | +* Adds or removes the ``disabled`` class from the permissions tab based on the checkbox state. |
| 48 | + |
| 49 | +To implement inactive states for tabs: |
| 50 | + |
| 51 | +1. Assign unique IDs to your tab elements. |
| 52 | +2. Use JavaScript to toggle the ``disabled`` class on the appropriate ``<li>`` elements. |
| 53 | + |
| 54 | +.. note:: |
| 55 | + Always use inactive states instead of hiding elements. |
0 commit comments