Skip to content

Commit

Permalink
Merge pull request #317 from DuneSt/hoemac-176-MDLTabWidget-should-sa…
Browse files Browse the repository at this point in the history
…ve-the-current-tab-for-refresh

draft : Hoemac 176 mdl tab widget should save the current tab for refresh
  • Loading branch information
LesageYann authored Nov 8, 2021
2 parents c089a80 + c3b716f commit c40aaba
Showing 1 changed file with 34 additions and 16 deletions.
50 changes: 34 additions & 16 deletions src/Material-Design-Lite-Widgets/MDLTabWidget.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@ Class {
#name : #MDLTabWidget,
#superclass : #MDLHighLevelWidget,
#instVars : [
'tabs'
'tabs',
'selectedTabIndex'
],
#category : 'Material-Design-Lite-Widgets-Tab'
#category : #'Material-Design-Lite-Widgets-Tab'
}

{ #category : #adding }
Expand All @@ -18,27 +19,44 @@ MDLTabWidget >> addTabNamed: aString content: anObject [
{ #category : #initialization }
MDLTabWidget >> initialize [
super initialize.
tabs := OrderedDictionary new
tabs := OrderedDictionary new.
selectedTabIndex := 1
]

{ #category : #rendering }
MDLTabWidget >> renderContentOn: html [
self ensureId: html.

self ensureId: html.
html mdlTabs
id: self id;
with: [ | tabIds |
with: [
| tabIds |
tabIds := Dictionary new.
html
mdlTabBar: [ tabs
keysAndValuesDo: [ :label :tabContent |
html mdlTabBar: [
tabs keysAndValuesDo: [ :label :tabContent |
html mdlTab
url: '#' , (tabIds at: tabContent ifAbsentPut: [ html nextId ]);
isActiveIf: (tabs indexOfKey: label) = 1;
url:
'#' , (tabIds at: tabContent ifAbsentPut: [ html nextId ]);

onClick: (html jQuery ajax callback: [
self selectedTabIndex: (tabs indexOfKey: label) ]);
isActiveIf: (tabs indexOfKey: label) = self selectedTabIndex;
with: label ] ].
tabs
keysAndValuesDo: [ :label :tabContent |
html mdlTabsPanel
id: (tabIds at: tabContent);
isActiveIf: (tabs indexOfKey: label) = 1;
with: tabContent ] ]
tabs keysAndValuesDo: [ :label :tabContent |
html mdlTabsPanel
id: (tabIds at: tabContent);
isActiveIf: (tabs indexOfKey: label) = self selectedTabIndex;
with: tabContent ] ]
]

{ #category : #accessing }
MDLTabWidget >> selectedTabIndex [

^selectedTabIndex
]

{ #category : #accessing }
MDLTabWidget >> selectedTabIndex: aNumber [

selectedTabIndex := aNumber
]

0 comments on commit c40aaba

Please sign in to comment.