Skip to content

Commit

Permalink
fix: missing disabled state for tab (#2249)
Browse files Browse the repository at this point in the history
fix: padding for tab-panel
  • Loading branch information
nmerget authored Feb 23, 2024
1 parent 25de895 commit 2bad9bd
Show file tree
Hide file tree
Showing 22 changed files with 57 additions and 24 deletions.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions packages/components/src/components/tab/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ export type DBTabDefaultProps = {
* Define the text next to the icon specified via the icon Property to get hidden.
*/
noText?: boolean;
/**
* The disabled attribute can be set to keep a user from clicking on the tab.
*/
disabled?: boolean;
};

export type DBTabProps = GlobalProps &
Expand Down
7 changes: 6 additions & 1 deletion packages/components/src/components/tab/tab.lite.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,12 @@ export default function DBTab(props: DBTabProps) {
<Show when={state.stylePath}>
<link rel="stylesheet" href={state.stylePath} />
</Show>
<input ref={ref} type="radio" id={state._id} />
<input
disabled={props.disabled}
ref={ref}
type="radio"
id={state._id}
/>

<Show when={props.label}>{props.label}</Show>
{props.children}
Expand Down
4 changes: 4 additions & 0 deletions packages/components/src/components/tab/tab.scss
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@
white-space: nowrap;
position: relative;

&:has(input:disabled) {
opacity: variables.$db-opacity-sm;
}

input {
&[type="radio"] {
position: absolute;
Expand Down
35 changes: 23 additions & 12 deletions packages/components/src/components/tabs/tabs.lite.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,16 @@ export default function DBTabs(props: DBTabsProps) {
if (childTabLists?.length > 0) {
const firstTabList = childTabLists.item(0);
if (firstTabList) {
firstTabList.setAttribute(
'aria-orientation',
props.orientation || 'horizontal'
);
if (
!firstTabList
.getAttributeNames()
.includes('aria-orientation')
) {
firstTabList.setAttribute(
'aria-orientation',
props.orientation || 'horizontal'
);
}

if (props.behaviour === 'arrows') {
const scrollContainers =
Expand All @@ -105,14 +111,19 @@ export default function DBTabs(props: DBTabsProps) {
if (tabs?.length > 0) {
Array.from<Element>(tabs).forEach(
(tab: Element, index: number) => {
tab.setAttribute(
'data-width',
props.width || 'auto'
);
tab.setAttribute(
'data-alignment',
props.alignment || 'start'
);
const attributes = tab.getAttributeNames();
if (!attributes.includes('data-width')) {
tab.setAttribute(
'data-width',
props.width || 'auto'
);
}
if (!attributes.includes('data-alignment')) {
tab.setAttribute(
'data-alignment',
props.alignment || 'start'
);
}

const input = tab.getElementsByTagName('input');
if (input.length > 0) {
Expand Down
8 changes: 8 additions & 0 deletions packages/components/src/components/tabs/tabs.scss
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,16 @@ $max-tabs: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
inline-size: 100%;
position: relative;

.db-tab-panel {
padding: 0 variables.$db-spacing-fixed-sm;
}

&[data-orientation="vertical"] {
flex-direction: row;

.db-tab-panel {
padding: variables.$db-spacing-fixed-sm 0;
}
}

.db-tab-list {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
[iconAfter]="exampleProps.iconAfter"
[width]="exampleProps.width"
[alignment]="exampleProps.alignment"
[disabled]="exampleProps.disabled"
>
{{ exampleName }}
</db-tab>
Expand Down
4 changes: 3 additions & 1 deletion showcases/react-showcase/src/components/tab/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,16 @@ const getTab = ({
icon,
iconAfter,
width,
alignment
alignment,
disabled
}: DBTabProps) => (
<DBTab
active={active}
noText={noText}
icon={icon}
iconAfter={iconAfter}
width={width}
disabled={disabled}
alignment={alignment}>
{children}
</DBTab>
Expand Down
17 changes: 7 additions & 10 deletions showcases/shared/tab.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,18 +30,23 @@
"examples": [
{
"name": "(Default) Enabled",
"className": "tab-hide-article",
"props": {
"label": "(Default) Enabled"
}
},
{
"name": "active",
"className": "tab-hide-article",
"props": {
"label": "active",
"active": true
}
},
{
"name": "disabled",
"props": {
"label": "active",
"disabled": true
}
}
]
},
Expand All @@ -50,30 +55,26 @@
"examples": [
{
"name": "(Default) Text",
"className": "tab-hide-article",
"props": {
"label": "(Default) Text"
}
},
{
"name": "Text - Icon (Leading)",
"className": "tab-hide-article",
"props": {
"label": "Text - Icon (Leading)",
"icon": "x_placeholder"
}
},
{
"name": "Text - Icon (Trailing)",
"className": "tab-hide-article",
"props": {
"label": "Text - Icon (Trailing)",
"iconAfter": "x_placeholder"
}
},
{
"name": "Icon",
"className": "tab-hide-article",
"props": {
"icon": "x_placeholder",
"noText": true
Expand All @@ -86,14 +87,12 @@
"examples": [
{
"name": "Auto Width (Default)",
"className": "tab-hide-article",
"props": {
"label": "Auto Width (Default)"
}
},
{
"name": "Width full",
"className": "tab-hide-article",
"style": { "width": "500px" },
"props": {
"label": "Width full",
Expand All @@ -107,7 +106,6 @@
"examples": [
{
"name": "Left",
"className": "tab-hide-article",
"style": { "width": "500px" },
"props": {
"label": "Left",
Expand All @@ -116,7 +114,6 @@
},
{
"name": "Centered",
"className": "tab-hide-article",
"style": { "width": "500px" },
"props": {
"label": "Centered",
Expand Down
1 change: 1 addition & 0 deletions showcases/vue-showcase/src/components/tab/Tab.vue
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { DBTab } from "../../../../../output/vue/vue3/src";
:iconAfter="exampleProps.iconAfter"
:width="exampleProps.width"
:alignment="exampleProps.alignment"
:disabled="exampleProps.disabled"
>
{{ exampleName }}
</DBTab>
Expand Down

0 comments on commit 2bad9bd

Please sign in to comment.